mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 03:05:28 -05:00
Merge commit '8bb78ab0d6bf95eea46d0cdedd8462525f2e1f7d' for sequence (fix bug)
This commit is contained in:
commit
6e031a7c03
7 changed files with 55 additions and 30 deletions
5
Makefile
5
Makefile
|
|
@ -108,4 +108,7 @@ update_next_tag:
|
|||
sed -i "s/NEXT_VERSION/$(VERSION)/g" **/*.ml **/*.mli
|
||||
sed -i "s/NEXT_RELEASE/$(VERSION)/g" **/*.ml **/*.mli
|
||||
|
||||
.PHONY: examples push_doc tags qtest
|
||||
udpate_sequence:
|
||||
git subtree pull --prefix sequence sequence stable --squash
|
||||
|
||||
.PHONY: examples push_doc tags qtest update_sequence
|
||||
|
|
|
|||
|
|
@ -1,5 +1,9 @@
|
|||
# Changelog
|
||||
|
||||
## 0.5.3
|
||||
|
||||
- bugfix: interaction between `take` and `is_empty`
|
||||
|
||||
## 0.5.2
|
||||
|
||||
- bugfix in `take`
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
# OASIS_START
|
||||
# DO NOT EDIT (digest: f4f3ee8dc8cda763af26a927b88956e6)
|
||||
version = "0.5.2"
|
||||
# DO NOT EDIT (digest: 99194977427ba82f5912e81125f6cac0)
|
||||
version = "0.5.3"
|
||||
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.2"
|
||||
version = "0.5.3"
|
||||
description = "Simple sequence (iterator) datatype and combinators"
|
||||
requires = "sequence delimcc"
|
||||
archive(byte) = "invert.cma"
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
OASISFormat: 0.4
|
||||
Name: sequence
|
||||
Version: 0.5.2
|
||||
Version: 0.5.3
|
||||
Homepage: https://github.com/c-cube/sequence
|
||||
Authors: Simon Cruanes
|
||||
License: BSD-2-clause
|
||||
|
|
@ -45,7 +45,7 @@ Document sequence
|
|||
XOCamlbuildLibraries: sequence
|
||||
|
||||
Test all
|
||||
Type: custom
|
||||
Type: custom (0.4)
|
||||
Command: make run-tests
|
||||
TestTools: run_tests
|
||||
Run$: flag(tests)
|
||||
|
|
|
|||
|
|
@ -319,33 +319,37 @@ let min ?(lt=fun x y -> x < y) seq =
|
|||
| Some y -> if lt x y then ret := Some x);
|
||||
!ret
|
||||
|
||||
exception ExitSequence
|
||||
exception ExitHead
|
||||
|
||||
let head seq =
|
||||
let r = ref None in
|
||||
try
|
||||
seq (fun x -> r := Some x; raise ExitSequence); None
|
||||
with ExitSequence -> !r
|
||||
seq (fun x -> r := Some x; raise ExitHead); None
|
||||
with ExitHead -> !r
|
||||
|
||||
let head_exn seq =
|
||||
match head seq with
|
||||
| None -> invalid_arg "Sequence.head_exn"
|
||||
| Some x -> x
|
||||
|
||||
exception ExitTake
|
||||
|
||||
let take n seq k =
|
||||
let count = ref 0 in
|
||||
try
|
||||
seq (fun x ->
|
||||
if !count = n then raise ExitSequence;
|
||||
if !count = n then raise ExitTake;
|
||||
incr count;
|
||||
k x;
|
||||
)
|
||||
with ExitSequence -> ()
|
||||
with ExitTake -> ()
|
||||
|
||||
exception ExitTakeWhile
|
||||
|
||||
let take_while p seq k =
|
||||
try
|
||||
seq (fun x -> if p x then k x else raise ExitSequence)
|
||||
with ExitSequence -> ()
|
||||
seq (fun x -> if p x then k x else raise ExitTakeWhile)
|
||||
with ExitTakeWhile -> ()
|
||||
|
||||
let drop n seq k =
|
||||
let count = ref 0 in
|
||||
|
|
@ -362,29 +366,35 @@ let rev seq =
|
|||
let l = MList.of_seq seq in
|
||||
fun k -> MList.iter_rev k l
|
||||
|
||||
exception ExitForall
|
||||
|
||||
let for_all p seq =
|
||||
try
|
||||
seq (fun x -> if not (p x) then raise ExitSequence);
|
||||
seq (fun x -> if not (p x) then raise ExitForall);
|
||||
true
|
||||
with ExitSequence -> false
|
||||
with ExitForall -> false
|
||||
|
||||
exception ExitExists
|
||||
|
||||
(** Exists there some element satisfying the predicate? *)
|
||||
let exists p seq =
|
||||
try
|
||||
seq (fun x -> if p x then raise ExitSequence);
|
||||
seq (fun x -> if p x then raise ExitExists);
|
||||
false
|
||||
with ExitSequence -> true
|
||||
with ExitExists -> true
|
||||
|
||||
let mem ?(eq=(=)) x seq = exists (eq x) seq
|
||||
|
||||
exception ExitFind
|
||||
|
||||
let find f seq =
|
||||
let r = ref None in
|
||||
begin try
|
||||
seq (fun x -> match f x with
|
||||
| None -> ()
|
||||
| Some _ as res -> r := res
|
||||
| Some _ as res -> r := res; raise ExitFind
|
||||
);
|
||||
with ExitSequence -> ()
|
||||
with ExitFind -> ()
|
||||
end;
|
||||
!r
|
||||
|
||||
|
|
@ -393,17 +403,19 @@ let length seq =
|
|||
seq (fun _ -> incr r);
|
||||
!r
|
||||
|
||||
exception ExitIsEmpty
|
||||
|
||||
let is_empty seq =
|
||||
try seq (fun _ -> raise ExitSequence); true
|
||||
with ExitSequence -> false
|
||||
try seq (fun _ -> raise ExitIsEmpty); true
|
||||
with ExitIsEmpty -> false
|
||||
|
||||
(** {2 Transform a sequence} *)
|
||||
|
||||
let empty2 k = ()
|
||||
|
||||
let is_empty2 seq2 =
|
||||
try ignore (seq2 (fun _ _ -> raise ExitSequence)); true
|
||||
with ExitSequence -> false
|
||||
try ignore (seq2 (fun _ _ -> raise ExitIsEmpty)); true
|
||||
with ExitIsEmpty -> false
|
||||
|
||||
let length2 seq2 =
|
||||
let r = ref 0 in
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
(* setup.ml generated for the first time by OASIS v0.4.4 *)
|
||||
|
||||
(* OASIS_START *)
|
||||
(* DO NOT EDIT (digest: 3e1599f233d66e02cd17bbb3a1c71d9e) *)
|
||||
(* DO NOT EDIT (digest: 1c260750474eb19b8e9212954217b6fd) *)
|
||||
(*
|
||||
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.2";
|
||||
version = "0.5.3";
|
||||
license =
|
||||
OASISLicense.DEP5License
|
||||
(OASISLicense.DEP5Unit
|
||||
|
|
@ -7044,7 +7044,7 @@ let setup_t =
|
|||
cs_plugin_data = []
|
||||
},
|
||||
{
|
||||
test_type = (`Test, "custom", None);
|
||||
test_type = (`Test, "custom", Some "0.4");
|
||||
test_command =
|
||||
[(OASISExpr.EBool true, ("make", ["run-tests"]))];
|
||||
test_custom =
|
||||
|
|
@ -7192,8 +7192,7 @@ let setup_t =
|
|||
};
|
||||
oasis_fn = Some "_oasis";
|
||||
oasis_version = "0.4.4";
|
||||
oasis_digest =
|
||||
Some "\142\243\242-\024\139\245\030\1867\186\147D\175\251\192";
|
||||
oasis_digest = Some "\214\tqh\b\169>\243\237\213\012\180\162\155`L";
|
||||
oasis_exec = None;
|
||||
oasis_setup_args = [];
|
||||
setup_update = false
|
||||
|
|
@ -7201,6 +7200,6 @@ let setup_t =
|
|||
|
||||
let setup () = BaseSetup.setup setup_t;;
|
||||
|
||||
# 7205 "setup.ml"
|
||||
# 7204 "setup.ml"
|
||||
(* OASIS_STOP *)
|
||||
let () = setup ();;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,8 @@ open Sequence.Infix
|
|||
|
||||
let pp_ilist l =
|
||||
let b = Buffer.create 15 in
|
||||
Format.bprintf b "@[<h>%a@]" (S.pp_seq Format.pp_print_int) (S.of_list l);
|
||||
let fmt = Format.formatter_of_buffer b in
|
||||
Format.fprintf fmt "@[<h>%a@]" (S.pp_seq Format.pp_print_int) (S.of_list l);
|
||||
Buffer.contents b
|
||||
|
||||
let test_empty () =
|
||||
|
|
@ -197,6 +198,11 @@ let test_take () =
|
|||
OUnit.assert_equal ~printer:pp_ilist [1;2;3;4;5] l;
|
||||
()
|
||||
|
||||
let test_regression1 () =
|
||||
let s = S.(take 10 (repeat 1)) in
|
||||
OUnit.assert_bool "not empty" (not (S.is_empty s));
|
||||
()
|
||||
|
||||
let suite =
|
||||
"test_sequence" >:::
|
||||
[ "test_empty" >:: test_empty;
|
||||
|
|
@ -225,4 +231,5 @@ let suite =
|
|||
"test_hashtbl" >:: test_hashtbl;
|
||||
"test_int_range" >:: test_int_range;
|
||||
"test_take" >:: test_take;
|
||||
"test_regression1" >:: test_regression1
|
||||
]
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue