diff --git a/src/sequence.ml b/src/sequence.ml index 96d2452..b5ce58d 100644 --- a/src/sequence.ml +++ b/src/sequence.ml @@ -133,9 +133,7 @@ let concat s k = s (fun s' -> s' k) let flatten s = concat s -let flatMap f seq k = seq (fun x -> f x k) - -let flat_map = flatMap +let flat_map f seq k = seq (fun x -> f x k) (*$R (1 -- 1000) @@ -147,14 +145,12 @@ let flat_map = flatMap let flat_map_l f seq k = seq (fun x -> List.iter k (f x)) -let fmap f seq k = +let filter_map f seq k = seq (fun x -> match f x with | None -> () | Some y -> k y ) -let filter_map = fmap - let intersperse elem seq k = let first = ref true in seq (fun x -> (if !first then first := false else k elem); k x) @@ -337,8 +333,6 @@ let group_succ_by ?(eq=fun x y -> x = y) seq k = (* last list *) if !cur <> [] then k !cur -let group = group_succ_by - (*$R [1;2;3;3;2;2;3;4] |> of_list |> group_succ_by ?eq:None |> to_list diff --git a/src/sequence.mli b/src/sequence.mli index 9a501ce..379a158 100644 --- a/src/sequence.mli +++ b/src/sequence.mli @@ -150,23 +150,19 @@ val concat : 'a t t -> 'a t val flatten : 'a t t -> 'a t (** Alias for {!concat} *) -val flatMap : ('a -> 'b t) -> 'a t -> 'b t -(** @deprecated use {!flat_map} since 0.6 *) - val flat_map : ('a -> 'b t) -> 'a t -> 'b t (** Monadic bind. Intuitively, it applies the function to every element of the initial sequence, and calls {!concat}. + Formerly [flatMap] @since 0.5 *) val flat_map_l : ('a -> 'b list) -> 'a t -> 'b t (** Convenience function combining {!flat_map} and {!of_list} @since NEXT_RELEASE *) -val fmap : ('a -> 'b option) -> 'a t -> 'b t -(** @deprecated use {!filter_map} since 0.6 *) - val filter_map : ('a -> 'b option) -> 'a t -> 'b t (** Map and only keep non-[None] elements + Formerly [fmap] @since 0.5 *) val intersperse : 'a -> 'a t -> 'a t @@ -201,13 +197,9 @@ val sort : ?cmp:('a -> 'a -> int) -> 'a t -> 'a t val sort_uniq : ?cmp:('a -> 'a -> int) -> 'a t -> 'a t (** Sort the sequence and remove duplicates. Eager, same as [sort] *) -val group : ?eq:('a -> 'a -> bool) -> 'a t -> 'a list t -(** Group equal consecutive elements. - @deprecated since 0.6 use {!group_succ_by} *) - val group_succ_by : ?eq:('a -> 'a -> bool) -> 'a t -> 'a list t (** Group equal consecutive elements. - Synonym to {!group}. + Formerly synonym to [group]. @since 0.6 *) val group_by : ?hash:('a -> int) -> ?eq:('a -> 'a -> bool) -> diff --git a/src/sequenceLabels.mli b/src/sequenceLabels.mli index 5db0707..1a092eb 100644 --- a/src/sequenceLabels.mli +++ b/src/sequenceLabels.mli @@ -126,14 +126,12 @@ val concat : 'a t t -> 'a t val flatten : 'a t t -> 'a t (** Alias for {!concat} *) -val flatMap : f:('a -> 'b t) -> 'a t -> 'b t -(** @deprecated use {!flat_map} *) - val flat_map : f:('a -> 'b t) -> 'a t -> 'b t (** Alias to {!flatMap} with a more explicit name *) -val fmap : f:('a -> 'b option) -> 'a t -> 'b t -(** @deprecated use {!filter_map} *) +val flat_map_l : f:('a -> 'b list) -> 'a t -> 'b t +(** Convenience function combining {!flat_map} and {!of_list} + @since NEXT_RELEASE *) val filter_map : f:('a -> 'b option) -> 'a t -> 'b t (** Alias to {!fmap} with a more explicit name *) @@ -170,8 +168,16 @@ val sort : ?cmp:('a -> 'a -> int) -> 'a t -> 'a t val sort_uniq : ?cmp:('a -> 'a -> int) -> 'a t -> 'a t (** Sort the sequence and remove duplicates. Eager, same as [sort] *) -val group : ?eq:('a -> 'a -> bool) -> 'a t -> 'a list t -(** Group equal consecutive elements. *) +val group_succ_by : ?eq:('a -> 'a -> bool) -> 'a t -> 'a list t +(** Group equal consecutive elements. + Formerly synonym to [group]. + @since 0.6 *) + +val group_by : ?hash:('a -> int) -> ?eq:('a -> 'a -> bool) -> + 'a t -> 'a list t +(** Group equal elements, disregarding their order of appearance. + The result sequence is traversable as many times as required. + @since 0.6 *) val uniq : ?eq:('a -> 'a -> bool) -> 'a t -> 'a t (** Remove consecutive duplicate elements. Basically this is @@ -369,6 +375,13 @@ val int_range_dec : start:int -> stop:int -> int t (** Iterator on decreasing integers in [stop...start] by steps -1. See {!(--^)} for an infix version *) +val int_range_by : step:int -> start:int -> stop:int -> int t +(** [int_range_by ~step ~start:i ~stop:j] is the range starting at [i], including [j], + where the difference between successive elements is [step]. + use a negative [step] for a decreasing sequence. + @since NEXT_RELEASE + @raise Invalid_argument if [step=0] *) + val of_set : (module Set.S with type elt = 'a and type t = 'b) -> 'b -> 'a t (** Convert the given set to a sequence. The set module must be provided. *)