mirror of
https://github.com/c-cube/iter.git
synced 2025-12-06 11:15:32 -05:00
of_list/to_list in Map/Set adapters
This commit is contained in:
parent
4475d52b0f
commit
fea71526b0
3 changed files with 20 additions and 2 deletions
1
_oasis
1
_oasis
|
|
@ -47,6 +47,7 @@ Document sequence
|
||||||
Test all
|
Test all
|
||||||
Type: custom
|
Type: custom
|
||||||
Command: make run-tests
|
Command: make run-tests
|
||||||
|
TestTools: run_tests
|
||||||
Run$: flag(tests)
|
Run$: flag(tests)
|
||||||
|
|
||||||
Executable run_tests
|
Executable run_tests
|
||||||
|
|
|
||||||
14
sequence.ml
14
sequence.ml
|
|
@ -576,14 +576,20 @@ module Set = struct
|
||||||
include Set.S
|
include Set.S
|
||||||
val of_seq : elt sequence -> t
|
val of_seq : elt sequence -> t
|
||||||
val to_seq : t -> elt sequence
|
val to_seq : t -> elt sequence
|
||||||
|
val to_list : t -> elt list
|
||||||
|
val of_list : elt list -> t
|
||||||
end
|
end
|
||||||
|
|
||||||
(** Create an enriched Set module from the given one *)
|
(** Create an enriched Set module from the given one *)
|
||||||
module Adapt(X : Set.S) = struct
|
module Adapt(X : Set.S) = struct
|
||||||
let to_seq set = from_iter (fun k -> X.iter k set)
|
let to_seq set k = X.iter k set
|
||||||
|
|
||||||
let of_seq seq = fold (fun set x -> X.add x set) X.empty seq
|
let of_seq seq = fold (fun set x -> X.add x set) X.empty seq
|
||||||
|
|
||||||
|
let of_list l = of_seq (of_list l)
|
||||||
|
|
||||||
|
let to_list set = to_list (to_seq set)
|
||||||
|
|
||||||
include X
|
include X
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -603,6 +609,8 @@ module Map = struct
|
||||||
val of_seq : (key * 'a) sequence -> 'a t
|
val of_seq : (key * 'a) sequence -> 'a t
|
||||||
val keys : 'a t -> key sequence
|
val keys : 'a t -> key sequence
|
||||||
val values : 'a t -> 'a sequence
|
val values : 'a t -> 'a sequence
|
||||||
|
val to_list : 'a t -> (key * 'a) list
|
||||||
|
val of_list : (key * 'a) list -> 'a t
|
||||||
end
|
end
|
||||||
|
|
||||||
(** Adapt a pre-existing Map module to make it sequence-aware *)
|
(** Adapt a pre-existing Map module to make it sequence-aware *)
|
||||||
|
|
@ -615,6 +623,10 @@ module Map = struct
|
||||||
|
|
||||||
let values m = from_iter (fun k -> M.iter (fun _ y -> k y) m)
|
let values m = from_iter (fun k -> M.iter (fun _ y -> k y) m)
|
||||||
|
|
||||||
|
let of_list l = of_seq (of_list l)
|
||||||
|
|
||||||
|
let to_list x = to_list (to_seq x)
|
||||||
|
|
||||||
include M
|
include M
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -378,7 +378,8 @@ exception OneShotSequence
|
||||||
val of_in_channel : in_channel -> char t
|
val of_in_channel : in_channel -> char t
|
||||||
(** Iterates on characters of the input (can block when one
|
(** Iterates on characters of the input (can block when one
|
||||||
iterates over the sequence). If you need to iterate
|
iterates over the sequence). If you need to iterate
|
||||||
several times on this sequence, use {!persistent}. *)
|
several times on this sequence, use {!persistent}.
|
||||||
|
@raise OneShotSequence when used more than once. *)
|
||||||
|
|
||||||
val to_buffer : char t -> Buffer.t -> unit
|
val to_buffer : char t -> Buffer.t -> unit
|
||||||
(** Copy content of the sequence into the buffer *)
|
(** Copy content of the sequence into the buffer *)
|
||||||
|
|
@ -419,6 +420,8 @@ module Set : sig
|
||||||
include Set.S
|
include Set.S
|
||||||
val of_seq : elt sequence -> t
|
val of_seq : elt sequence -> t
|
||||||
val to_seq : t -> elt sequence
|
val to_seq : t -> elt sequence
|
||||||
|
val to_list : t -> elt list
|
||||||
|
val of_list : elt list -> t
|
||||||
end
|
end
|
||||||
|
|
||||||
(** Create an enriched Set module from the given one *)
|
(** Create an enriched Set module from the given one *)
|
||||||
|
|
@ -437,6 +440,8 @@ module Map : sig
|
||||||
val of_seq : (key * 'a) sequence -> 'a t
|
val of_seq : (key * 'a) sequence -> 'a t
|
||||||
val keys : 'a t -> key sequence
|
val keys : 'a t -> key sequence
|
||||||
val values : 'a t -> 'a sequence
|
val values : 'a t -> 'a sequence
|
||||||
|
val to_list : 'a t -> (key * 'a) list
|
||||||
|
val of_list : (key * 'a) list -> 'a t
|
||||||
end
|
end
|
||||||
|
|
||||||
(** Adapt a pre-existing Map module to make it sequence-aware *)
|
(** Adapt a pre-existing Map module to make it sequence-aware *)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue