Add on_list.

This commit is contained in:
Drup 2014-08-08 20:37:54 +02:00
parent 3458581ff2
commit ae390d34f4
2 changed files with 10 additions and 4 deletions

View file

@ -436,14 +436,17 @@ let to_list seq = List.rev (fold (fun y x -> x::y) [] seq)
let to_rev_list seq = fold (fun y x -> x :: y) [] seq let to_rev_list seq = fold (fun y x -> x :: y) [] seq
let of_list l k = List.iter k l
let on_list f l =
to_list (f (of_list l))
let to_opt = head let to_opt = head
let of_opt o k = match o with let of_opt o k = match o with
| None -> () | None -> ()
| Some x -> k x | Some x -> k x
let of_list l k = List.iter k l
let to_array seq = let to_array seq =
let l = MList.of_seq seq in let l = MList.of_seq seq in
let n = MList.length l in let n = MList.length l in
@ -767,5 +770,3 @@ module IO = struct
let write_lines ?mode ?flags filename seq = let write_lines ?mode ?flags filename seq =
write_to ?mode ?flags filename (snoc (intersperse "\n" seq) "\n") write_to ?mode ?flags filename (snoc (intersperse "\n" seq) "\n")
end end

View file

@ -319,6 +319,11 @@ val to_rev_list : 'a t -> 'a list
val of_list : 'a list -> 'a t val of_list : 'a list -> 'a t
val on_list : ('a t -> 'b t) -> 'a list -> 'b list
(** [on_list f l] is equivalent to [to_list @@ f @@ of_list l].
@since NEXT_RELEASE
*)
val to_opt : 'a t -> 'a option val to_opt : 'a t -> 'a option
(** Alias to {!head} (** Alias to {!head}
@since NEXT_RELEASE *) @since NEXT_RELEASE *)