Module Fang_iter.Iter

type 'a t = 'a iter

Building iterators

val empty : _ t

empty is an iterator which doesn't iterate over any values.

val one : 'a -> 'a t

one x iterates over the value x and no others.

val adapt : (('a -> unit) -> 'b -> unit) -> 'b -> 'a t

The modules for many standard containers already have a function for invoking a function to each item.

For example,

List.iter (fun x -> print_int x) [1; 2; 3] 

willy invoke fun x -> print_int x for each item in the list.

adapt f xs produces an iterator for a container xs given an iteration function f like List.iter.

For example,

adapt List.iter [1; 2; 3] 

is an int t which will iterate over the values [1; 2; 3].

val adapt2 : (('a -> 'b -> unit) -> 'c -> unit) -> 'c -> ('a * 'b) t
val cons : 'a -> 'a t -> 'a t

cons x xs iterates first over the value x and then values iterated over by xs.

val concat : 'a t -> 'a t -> 'a t

concat xs ys iterates over the values iterated over by xs and then the values iterated over by ys.

Transformations

val flat_map : ('a -> 'b t) -> 'a t -> 'b t
val filter : ('a -> bool) -> 'a t -> 'a t
val filter_map : ('a -> 'b option) -> 'a t -> 'b t
val map : ('a -> 'b) -> 'a t -> 'b t

Searching

val find_first : ('a -> bool) -> 'a t -> 'a option
val maximum : ('a -> 'a -> int) -> 'a t -> 'a option
val all : ('a -> bool) -> 'a t -> bool
val first : 'a t -> 'a option

Folding

val fold : 'b -> ('b -> 'a -> 'b) -> 'a t -> 'b
val into_set : (module Stdlib.Set.S with type elt = 'a and type t = 'b) -> 'a t -> 'b
val into_list : 'a t -> 'a list
val count : _ t -> int

Pretty-printing

val pp : ?⁠sep:unit Fmt.t -> 'a Fmt.t -> 'a t Fmt.t