package devkit

  1. Overview
  2. Docs

Extensions to Enum

include module type of Enum with type 'a t = 'a Enum.t
type 'a t = 'a Enum.t
val iter : ('a -> unit) -> 'a t -> unit
val iter2 : ('a -> 'b -> unit) -> 'a t -> 'b t -> unit
val fold : ('a -> 'b -> 'b) -> 'b -> 'a t -> 'b
val fold2 : ('a -> 'b -> 'c -> 'c) -> 'c -> 'a t -> 'b t -> 'c
val iteri : (int -> 'a -> unit) -> 'a t -> unit
val iter2i : (int -> 'a -> 'b -> unit) -> 'a t -> 'b t -> unit
val foldi : (int -> 'a -> 'b -> 'b) -> 'b -> 'a t -> 'b
val fold2i : (int -> 'a -> 'b -> 'c -> 'c) -> 'c -> 'a t -> 'b t -> 'c
val find : ('a -> bool) -> 'a t -> 'a
val is_empty : 'a t -> bool
val peek : 'a t -> 'a option
val get : 'a t -> 'a option
val next : 'a t -> 'a
val push : 'a t -> 'a -> unit
val junk : 'a t -> unit
val clone : 'a t -> 'a t
val force : 'a t -> unit
val map : ('a -> 'b) -> 'a t -> 'b t
val mapi : (int -> 'a -> 'b) -> 'a t -> 'b t
val filter : ('a -> bool) -> 'a t -> 'a t
val filter_map : ('a -> 'b option) -> 'a t -> 'b t
val append : 'a t -> 'a t -> 'a t
val concat : 'a t t -> 'a t
exception No_more_elements
val empty : unit -> 'a t
val make : next:(unit -> 'a) -> count:(unit -> int) -> clone:(unit -> 'a t) -> 'a t
val from : (unit -> 'a) -> 'a t
val init : int -> (int -> 'a) -> 'a t
val count : 'a t -> int
val fast_count : 'a t -> bool
val find_peek : ('a -> bool) -> 'a t -> 'a

same as Enum.find, but found element is peeked, not junked

val list_loop : 'a list -> 'a t
  • returns

    enum that indefinitely runs over given (non-empty) list

val of_dynarray : ?start:int -> ?n:int -> 'a DynArray.t -> 'a Enum.t
  • returns

    enum over DynArray slice (default: whole array)

val take : int -> 'a t -> 'a t

take n e

  • returns

    enum consuming first n elements of e

val align : ('a -> 'a -> int) -> 'a t -> 'a t -> 'a t

merge two enums of same type

val join : ?left:bool -> ?right:bool -> ?multi:bool -> ('a -> 'b -> int) -> 'a t -> 'b t -> ('a option * 'b option) t
  • parameter multi

    repeat input value from the left enum multiple times to output as many pairs as there are matching equal consecutive values in the right enum

val join_assoc : ?left:bool -> ?right:bool -> ?multi:bool -> ('a -> 'a -> int) -> ('a * 'b) t -> ('a * 'c) t -> ('a * 'b option * 'c option) t
include module type of ExtEnum_merge
val join_inner_by : ('a -> 'b -> int) -> ('c -> 'a) -> ('d -> 'b) -> 'c Enum.t -> 'd Enum.t -> ('c * 'd) Enum.t
val join_inner_by_key : ('a -> 'a -> int) -> ('b -> 'a) -> 'b Enum.t -> 'b Enum.t -> ('b * 'b) Enum.t
val join_left_by : ('a -> 'b -> int) -> ('c -> 'a) -> ('d -> 'b) -> 'c Enum.t -> 'd Enum.t -> ('c * 'd option) Enum.t
val join_left_by_key : ('a -> 'a -> int) -> ('b -> 'a) -> 'b Enum.t -> 'b Enum.t -> ('b * 'b option) Enum.t
val join_right_by : ('a -> 'b -> int) -> ('c -> 'a) -> ('d -> 'b) -> 'c Enum.t -> 'd Enum.t -> ('c option * 'd) Enum.t
val join_right_by_key : ('a -> 'a -> int) -> ('b -> 'a) -> 'b Enum.t -> 'b Enum.t -> ('b option * 'b) Enum.t
val join_full_by : ('a -> 'b -> int) -> ('c -> 'a) -> ('d -> 'b) -> 'c Enum.t -> 'd Enum.t -> [> `Both of 'c * 'd | `Left of 'c | `Right of 'd ] Enum.t
val join_full_by_key : ('a -> 'a -> int) -> ('b -> 'a) -> 'b Enum.t -> 'b Enum.t -> [> `Both of 'b * 'b | `Left of 'b | `Right of 'b ] Enum.t
val join_inner_multi_by : ('a -> 'b -> int) -> ('c -> 'a) -> ('d -> 'b) -> 'c Enum.t -> 'd Enum.t -> ('c * 'd) Enum.t
val join_inner_multi_by_key : ('a -> 'a -> int) -> ('b -> 'a) -> 'b Enum.t -> 'b Enum.t -> ('b * 'b) Enum.t
val join_left_multi_by : ('a -> 'b -> int) -> ('c -> 'a) -> ('d -> 'b) -> 'c Enum.t -> 'd Enum.t -> ('c * 'd option) Enum.t
val join_left_multi_by_key : ('a -> 'a -> int) -> ('b -> 'a) -> 'b Enum.t -> 'b Enum.t -> ('b * 'b option) Enum.t
val join_right_multi_by : ('a -> 'b -> int) -> ('c -> 'a) -> ('d -> 'b) -> 'c Enum.t -> 'd Enum.t -> ('c option * 'd) Enum.t
val join_right_multi_by_key : ('a -> 'a -> int) -> ('b -> 'a) -> 'b Enum.t -> 'b Enum.t -> ('b option * 'b) Enum.t
val join_full_multi_by : ('a -> 'b -> int) -> ('c -> 'a) -> ('d -> 'b) -> 'c Enum.t -> 'd Enum.t -> [> `Both of 'c * 'd | `Left of 'c | `Right of 'd ] Enum.t
val join_full_multi_by_key : ('a -> 'a -> int) -> ('b -> 'a) -> 'b Enum.t -> 'b Enum.t -> [> `Both of 'b * 'b | `Left of 'b | `Right of 'b ] Enum.t
val join_assoc_inner : ('a -> 'b -> int) -> ('a * 'c) Enum.t -> ('b * 'd) Enum.t -> ('a * 'c * 'd) Enum.t
val join_assoc_left : ('a -> 'b -> int) -> ('a * 'c) Enum.t -> ('b * 'd) Enum.t -> ('a * 'c * 'd option) Enum.t
val join_assoc_right : ('a -> 'a -> int) -> ('a * 'b) Enum.t -> ('a * 'c) Enum.t -> ('a * 'b option * 'c) Enum.t
val join_assoc_full : ('a -> 'a -> int) -> ('a * 'b) Enum.t -> ('a * 'c) Enum.t -> ('a * [> `Both of 'b * 'c | `Left of 'b | `Right of 'c ]) Enum.t
val join_assoc_inner_multi : ('a -> 'b -> int) -> ('a * 'c) Enum.t -> ('b * 'd) Enum.t -> ('a * 'c * 'd) Enum.t
val join_assoc_left_multi : ('a -> 'b -> int) -> ('a * 'c) Enum.t -> ('b * 'd) Enum.t -> ('a * 'c * 'd option) Enum.t
val join_assoc_right_multi : ('a -> 'a -> int) -> ('a * 'b) Enum.t -> ('a * 'c) Enum.t -> ('a * 'b option * 'c) Enum.t
val join_assoc_full_multi : ('a -> 'a -> int) -> ('a * 'b) Enum.t -> ('a * 'c) Enum.t -> ('a * [> `Both of 'b * 'c | `Left of 'b | `Right of 'c ]) Enum.t
val merge : ('a -> 'b -> int) -> 'a t -> 'b t -> ('a option * 'b option) t

merge two enums of different types

val merge_assoc : ('a -> 'a -> int) -> ('a * 'b) t -> ('a * 'c) t -> ('a * 'b option * 'c option) t

merge two enums over key-value pairs

val group : ('acc -> 'a -> bool) -> ('acc -> 'a -> 'acc) -> 'acc -> 'a t -> 'acc t

group equal fold zero e accumulates elements of e with fold, first element is folded with zero, at each subsequent step equal is checked, and new accumulator is started once it returns false

val group_assoc : ('a -> 'a -> bool) -> ('b -> 'c -> 'b) -> 'b -> ('a * 'c) t -> ('a * 'b) t

group_assoc equal fold zero e accumulates (with fold) values in e with matching key as determined by comparison function equal, first value is folded with zero, e.g.:

List.of_enum @@ Enum.group_assoc (=) (+) 0 @@ List.enum ["a",1; "a",2; "b",3; "b",4; "a", 1; "a", 10] = ["a", 3; "b", 7; "a", 11; ]

val uniq : ('a -> 'a -> bool) -> 'a t -> 'a t

uniq f e replaces every consecuitive sequence of elements from e comparing equal by the given comparison function f with the first element from that sequence

val count_unique : ('a -> 'a -> bool) -> 'a t -> ('a * int) t

count_unique f e replaces every consecutive sequence of elements from e comparing equal by the given comparison function f with the first element from that sequence and the number of duplicates

val sub : ?eq:('b -> 'b -> bool) -> 'a t -> ('a -> 'b) -> ('b * 'a t) option

sub e f extracts a subenum (consecutive sequence of the elements from e) that map to the same value of f

val iter_while : ('a -> bool) -> 'a t -> unit

iter_while f e calls f for each element of e until it returns false or e is exhausted

OCaml

Innovation. Community. Security.