mirror of
https://github.com/c-cube/iter.git
synced 2025-12-06 11:15:32 -05:00
Add on_list.
This commit is contained in:
parent
3458581ff2
commit
ae390d34f4
2 changed files with 10 additions and 4 deletions
|
|
@ -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 of_list l k = List.iter k l
|
||||
|
||||
let on_list f l =
|
||||
to_list (f (of_list l))
|
||||
|
||||
let to_opt = head
|
||||
|
||||
let of_opt o k = match o with
|
||||
| None -> ()
|
||||
| Some x -> k x
|
||||
|
||||
let of_list l k = List.iter k l
|
||||
|
||||
let to_array seq =
|
||||
let l = MList.of_seq seq in
|
||||
let n = MList.length l in
|
||||
|
|
@ -767,5 +770,3 @@ module IO = struct
|
|||
let write_lines ?mode ?flags filename seq =
|
||||
write_to ?mode ?flags filename (snoc (intersperse "\n" seq) "\n")
|
||||
end
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -319,6 +319,11 @@ val to_rev_list : 'a t -> 'a list
|
|||
|
||||
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
|
||||
(** Alias to {!head}
|
||||
@since NEXT_RELEASE *)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue