diff --git a/src/data/CCFQueue.ml b/src/data/CCFQueue.ml index 4e4e141c..0f01245d 100644 --- a/src/data/CCFQueue.ml +++ b/src/data/CCFQueue.ml @@ -485,6 +485,18 @@ let (--) a b = 0 -- 0 |> to_list = [0] *) +let (--^) a b = + if a=b then empty + else if a to_list = [1;2;3;4] + 5 --^ 1 |> to_list = [5;4;3;2] + 1 --^ 2 |> to_list = [1] + 0 --^ 0 |> to_list = [] +*) + let print pp_x out d = let first = ref true in Format.fprintf out "@[queue {"; diff --git a/src/data/CCFQueue.mli b/src/data/CCFQueue.mli index 29c0b58d..7f81e42c 100644 --- a/src/data/CCFQueue.mli +++ b/src/data/CCFQueue.mli @@ -127,5 +127,9 @@ val (--) : int -> int -> int t (** [a -- b] is the integer range from [a] to [b], both included. @since 0.10 *) +val (--^) : int -> int -> int t +(** [a -- b] is the integer range from [a] to [b], where [b] is excluded. + @since NEXT_RELEASE *) + val print : 'a printer -> 'a t printer (** @since 0.13 *) diff --git a/src/data/CCRAL.ml b/src/data/CCRAL.ml index 697e2bb5..d2a39474 100644 --- a/src/data/CCRAL.ml +++ b/src/data/CCRAL.ml @@ -426,6 +426,18 @@ let range i j = range i j |> to_list = CCList.(i -- j) ) *) +let range_r_open_ i j = + if i=j then empty + else if i to_list) + [5;4;3;2] (5 --^ 1 |> to_list) + [1] (1 --^ 2 |> to_list) + [] (0 --^ 0 |> to_list) +*) + (** {2 Conversions} *) type 'a sequence = ('a -> unit) -> unit @@ -554,6 +566,7 @@ module Infix = struct let (>|=) l f = map ~f l let (<*>) = app let (--) = range + let (--^) = range_r_open_ end include Infix diff --git a/src/data/CCRAL.mli b/src/data/CCRAL.mli index 081645ce..f716b294 100644 --- a/src/data/CCRAL.mli +++ b/src/data/CCRAL.mli @@ -175,6 +175,10 @@ module Infix : sig val (--) : int -> int -> int t (** Alias to {!range} *) + + val (--^) : int -> int -> int t + (** [a -- b] is the integer range from [a] to [b], where [b] is excluded. + @since NEXT_RELEASE *) end include module type of Infix diff --git a/src/iter/CCKList.ml b/src/iter/CCKList.ml index e4d88428..d161df8c 100644 --- a/src/iter/CCKList.ml +++ b/src/iter/CCKList.ml @@ -253,6 +253,18 @@ let range i j = let (--) = range +let (--^) i j = + if i=j then empty + else if i to_list = [1;2;3;4] + 5 --^ 1 |> to_list = [5;4;3;2] + 1 --^ 2 |> to_list = [1] + 0 --^ 0 |> to_list = [] +*) + let rec fold2 f acc l1 l2 = match l1(), l2() with | `Nil, _ | _, `Nil -> acc @@ -475,6 +487,18 @@ let (<.>) f a = fair_app f a |> to_list |> List.sort Pervasives.compare = [2; 3; 11; 30] *) +(** {2 Infix} *) + +module Infix = struct + let (>>=) = (>>=) + let (>|=) = (>|=) + let (<*>) = (<*>) + let (>>-) = (>>-) + let (<.>) = (<.>) + let (--) = (--) + let (--^) = (--^) +end + (** {2 Monadic Operations} *) module type MONAD = sig type 'a t diff --git a/src/iter/CCKList.mli b/src/iter/CCKList.mli index 7fb1c879..ab96ff38 100644 --- a/src/iter/CCKList.mli +++ b/src/iter/CCKList.mli @@ -130,6 +130,12 @@ val flatten : 'a t t -> 'a t val range : int -> int -> int t val (--) : int -> int -> int t +(** [a -- b] is the range of integers containing + [a] and [b] (therefore, never empty) *) + +val (--^) : int -> int -> int t +(** [a -- b] is the integer range from [a] to [b], where [b] is excluded. + @since NEXT_RELEASE *) (** {2 Operations on two Collections} *) @@ -204,6 +210,20 @@ val (<.>) : ('a -> 'b) t -> 'a t -> 'b t (** Infix version of {!fair_app} @since 0.13 *) +(** {2 Infix operators} + + @since NEXT_RELEASE *) + +module Infix : sig + val (>>=) : 'a t -> ('a -> 'b t) -> 'b t + val (>|=) : 'a t -> ('a -> 'b) -> 'b t + val (<*>) : ('a -> 'b) t -> 'a t -> 'b t + val (>>-) : 'a t -> ('a -> 'b t) -> 'b t + val (<.>) : ('a -> 'b) t -> 'a t -> 'b t + val (--) : int -> int -> int t + val (--^) : int -> int -> int t +end + (** {2 Monadic Operations} *) module type MONAD = sig type 'a t