mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 19:25:28 -05:00
Merge commit '15665761b2d85469c1f0591cb976ba6956100cc5' for sequence
This commit is contained in:
commit
3a225f754f
8 changed files with 38 additions and 13 deletions
|
|
@ -329,6 +329,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 *)
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,10 @@
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 0.5.2
|
||||||
|
|
||||||
|
- bugfix in `take`
|
||||||
|
- `on_list` for mapping lists through sequences
|
||||||
|
|
||||||
## 0.5.1
|
## 0.5.1
|
||||||
|
|
||||||
- `Sequence.IO` module, a very very simple way to read/write files
|
- `Sequence.IO` module, a very very simple way to read/write files
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
# OASIS_START
|
# OASIS_START
|
||||||
# DO NOT EDIT (digest: 3b9ebef180f5e4bdb720d2103ba95667)
|
# DO NOT EDIT (digest: f4f3ee8dc8cda763af26a927b88956e6)
|
||||||
version = "0.5.1"
|
version = "0.5.2"
|
||||||
description = "Simple sequence (iterator) datatype and combinators"
|
description = "Simple sequence (iterator) datatype and combinators"
|
||||||
archive(byte) = "sequence.cma"
|
archive(byte) = "sequence.cma"
|
||||||
archive(byte, plugin) = "sequence.cma"
|
archive(byte, plugin) = "sequence.cma"
|
||||||
|
|
@ -8,7 +8,7 @@ archive(native) = "sequence.cmxa"
|
||||||
archive(native, plugin) = "sequence.cmxs"
|
archive(native, plugin) = "sequence.cmxs"
|
||||||
exists_if = "sequence.cma"
|
exists_if = "sequence.cma"
|
||||||
package "invert" (
|
package "invert" (
|
||||||
version = "0.5.1"
|
version = "0.5.2"
|
||||||
description = "Simple sequence (iterator) datatype and combinators"
|
description = "Simple sequence (iterator) datatype and combinators"
|
||||||
requires = "sequence delimcc"
|
requires = "sequence delimcc"
|
||||||
archive(byte) = "invert.cma"
|
archive(byte) = "invert.cma"
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
OASISFormat: 0.4
|
OASISFormat: 0.4
|
||||||
Name: sequence
|
Name: sequence
|
||||||
Version: 0.5.1
|
Version: 0.5.2
|
||||||
Homepage: https://github.com/c-cube/sequence
|
Homepage: https://github.com/c-cube/sequence
|
||||||
Authors: Simon Cruanes
|
Authors: Simon Cruanes
|
||||||
License: BSD-2-clause
|
License: BSD-2-clause
|
||||||
|
|
|
||||||
|
|
@ -336,9 +336,9 @@ let take n seq k =
|
||||||
let count = ref 0 in
|
let count = ref 0 in
|
||||||
try
|
try
|
||||||
seq (fun x ->
|
seq (fun x ->
|
||||||
|
if !count = n then raise ExitSequence;
|
||||||
incr count;
|
incr count;
|
||||||
k x;
|
k x;
|
||||||
if !count = n then raise ExitSequence
|
|
||||||
)
|
)
|
||||||
with ExitSequence -> ()
|
with ExitSequence -> ()
|
||||||
|
|
||||||
|
|
@ -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
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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 0.5.2
|
||||||
|
*)
|
||||||
|
|
||||||
val to_opt : 'a t -> 'a option
|
val to_opt : 'a t -> 'a option
|
||||||
(** Alias to {!head}
|
(** Alias to {!head}
|
||||||
@since 0.5.1 *)
|
@since 0.5.1 *)
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
(* setup.ml generated for the first time by OASIS v0.4.4 *)
|
(* setup.ml generated for the first time by OASIS v0.4.4 *)
|
||||||
|
|
||||||
(* OASIS_START *)
|
(* OASIS_START *)
|
||||||
(* DO NOT EDIT (digest: d7a207daf3186cce7792651a50aaba59) *)
|
(* DO NOT EDIT (digest: 3e1599f233d66e02cd17bbb3a1c71d9e) *)
|
||||||
(*
|
(*
|
||||||
Regenerated by OASIS v0.4.4
|
Regenerated by OASIS v0.4.4
|
||||||
Visit http://oasis.forge.ocamlcore.org for more information and
|
Visit http://oasis.forge.ocamlcore.org for more information and
|
||||||
|
|
@ -6826,7 +6826,7 @@ let setup_t =
|
||||||
alpha_features = [];
|
alpha_features = [];
|
||||||
beta_features = [];
|
beta_features = [];
|
||||||
name = "sequence";
|
name = "sequence";
|
||||||
version = "0.5.1";
|
version = "0.5.2";
|
||||||
license =
|
license =
|
||||||
OASISLicense.DEP5License
|
OASISLicense.DEP5License
|
||||||
(OASISLicense.DEP5Unit
|
(OASISLicense.DEP5Unit
|
||||||
|
|
@ -7192,7 +7192,8 @@ let setup_t =
|
||||||
};
|
};
|
||||||
oasis_fn = Some "_oasis";
|
oasis_fn = Some "_oasis";
|
||||||
oasis_version = "0.4.4";
|
oasis_version = "0.4.4";
|
||||||
oasis_digest = Some "8\252\157\1340^<0\133GR\029nmc6";
|
oasis_digest =
|
||||||
|
Some "\142\243\242-\024\139\245\030\1867\186\147D\175\251\192";
|
||||||
oasis_exec = None;
|
oasis_exec = None;
|
||||||
oasis_setup_args = [];
|
oasis_setup_args = [];
|
||||||
setup_update = false
|
setup_update = false
|
||||||
|
|
@ -7200,6 +7201,6 @@ let setup_t =
|
||||||
|
|
||||||
let setup () = BaseSetup.setup setup_t;;
|
let setup () = BaseSetup.setup setup_t;;
|
||||||
|
|
||||||
# 7204 "setup.ml"
|
# 7205 "setup.ml"
|
||||||
(* OASIS_STOP *)
|
(* OASIS_STOP *)
|
||||||
let () = setup ();;
|
let () = setup ();;
|
||||||
|
|
|
||||||
|
|
@ -190,6 +190,13 @@ let test_int_range () =
|
||||||
OUnit.assert_equal ~printer:pp_ilist [] S.(to_list (10 --^ 60));
|
OUnit.assert_equal ~printer:pp_ilist [] S.(to_list (10 --^ 60));
|
||||||
()
|
()
|
||||||
|
|
||||||
|
let test_take () =
|
||||||
|
let l = S.(to_list (take 0 (of_list [1]))) in
|
||||||
|
OUnit.assert_equal ~printer:pp_ilist [] l;
|
||||||
|
let l = S.(to_list (take 5 (of_list [1;2;3;4;5;6;7;8;9;10]))) in
|
||||||
|
OUnit.assert_equal ~printer:pp_ilist [1;2;3;4;5] l;
|
||||||
|
()
|
||||||
|
|
||||||
let suite =
|
let suite =
|
||||||
"test_sequence" >:::
|
"test_sequence" >:::
|
||||||
[ "test_empty" >:: test_empty;
|
[ "test_empty" >:: test_empty;
|
||||||
|
|
@ -217,4 +224,5 @@ let suite =
|
||||||
"test_unfoldr" >:: test_unfoldr;
|
"test_unfoldr" >:: test_unfoldr;
|
||||||
"test_hashtbl" >:: test_hashtbl;
|
"test_hashtbl" >:: test_hashtbl;
|
||||||
"test_int_range" >:: test_int_range;
|
"test_int_range" >:: test_int_range;
|
||||||
|
"test_take" >:: test_take;
|
||||||
]
|
]
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue