Merge commit '15665761b2d85469c1f0591cb976ba6956100cc5' for sequence

This commit is contained in:
Simon Cruanes 2014-08-08 23:54:39 +02:00
commit 3a225f754f
8 changed files with 38 additions and 13 deletions

View file

@ -329,6 +329,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 *)

View file

@ -1,5 +1,10 @@
# Changelog
## 0.5.2
- bugfix in `take`
- `on_list` for mapping lists through sequences
## 0.5.1
- `Sequence.IO` module, a very very simple way to read/write files

View file

@ -1,6 +1,6 @@
# OASIS_START
# DO NOT EDIT (digest: 3b9ebef180f5e4bdb720d2103ba95667)
version = "0.5.1"
# DO NOT EDIT (digest: f4f3ee8dc8cda763af26a927b88956e6)
version = "0.5.2"
description = "Simple sequence (iterator) datatype and combinators"
archive(byte) = "sequence.cma"
archive(byte, plugin) = "sequence.cma"
@ -8,7 +8,7 @@ archive(native) = "sequence.cmxa"
archive(native, plugin) = "sequence.cmxs"
exists_if = "sequence.cma"
package "invert" (
version = "0.5.1"
version = "0.5.2"
description = "Simple sequence (iterator) datatype and combinators"
requires = "sequence delimcc"
archive(byte) = "invert.cma"

View file

@ -1,6 +1,6 @@
OASISFormat: 0.4
Name: sequence
Version: 0.5.1
Version: 0.5.2
Homepage: https://github.com/c-cube/sequence
Authors: Simon Cruanes
License: BSD-2-clause

View file

@ -336,9 +336,9 @@ let take n seq k =
let count = ref 0 in
try
seq (fun x ->
if !count = n then raise ExitSequence;
incr count;
k x;
if !count = n then raise 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 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

View file

@ -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 0.5.2
*)
val to_opt : 'a t -> 'a option
(** Alias to {!head}
@since 0.5.1 *)

View file

@ -1,7 +1,7 @@
(* setup.ml generated for the first time by OASIS v0.4.4 *)
(* OASIS_START *)
(* DO NOT EDIT (digest: d7a207daf3186cce7792651a50aaba59) *)
(* DO NOT EDIT (digest: 3e1599f233d66e02cd17bbb3a1c71d9e) *)
(*
Regenerated by OASIS v0.4.4
Visit http://oasis.forge.ocamlcore.org for more information and
@ -6826,7 +6826,7 @@ let setup_t =
alpha_features = [];
beta_features = [];
name = "sequence";
version = "0.5.1";
version = "0.5.2";
license =
OASISLicense.DEP5License
(OASISLicense.DEP5Unit
@ -7192,7 +7192,8 @@ let setup_t =
};
oasis_fn = Some "_oasis";
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_setup_args = [];
setup_update = false
@ -7200,6 +7201,6 @@ let setup_t =
let setup () = BaseSetup.setup setup_t;;
# 7204 "setup.ml"
# 7205 "setup.ml"
(* OASIS_STOP *)
let () = setup ();;

View file

@ -190,6 +190,13 @@ let test_int_range () =
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 =
"test_sequence" >:::
[ "test_empty" >:: test_empty;
@ -217,4 +224,5 @@ let suite =
"test_unfoldr" >:: test_unfoldr;
"test_hashtbl" >:: test_hashtbl;
"test_int_range" >:: test_int_range;
"test_take" >:: test_take;
]