package alg_structs

  1. Overview
  2. Docs

Folds over optional values...

Option.fold_right ~f t ~init is f x init if t is Some x or init if t is None.

include Seed with type 'a t = 'a Option.t
type 'a t = 'a Option.t

The principle type, which can be folded over using fold_right.

val fold_right : f:('a -> 'b -> 'b) -> 'a t -> init:'b -> 'b

fold_right ~f t ~init combines the elements of t using f from the right.

val fold : (module Monoid.S with type t = 'a) -> 'a t -> 'a

fold m t folds the elements of t with m.op. E.g.,

# Foldable.List.fold (module Monoid.Int.Sum) [1;2;3;4];;
- : int = 10
val fold_map : m:(module Monoid.S with type t = 'm) -> f:('a -> 'm) -> 'a t -> 'm

fold_map ~m ~f t is a map of the elements of t in the monoid m combines with m.op.

E.g.,

# Foldable.List.fold_map ~m:(module Monoid.Int.Sum) ~f:int_of_string ["1";"2";"3";"4"];;
- : int = 10
val fold_left : f:('b -> 'a -> 'b) -> init:'b -> 'a t -> 'b

fold_left ~f ~init t combines the elements of t using f from the left.

val to_list : 'a t -> 'a list

to_list t is a list with the elements of t from left to right

val is_empty : 'a t -> bool

is_empty t is true when t is empty

val length : 'a t -> int

length t is the number of elements in t

val any : f:('a -> bool) -> 'a t -> bool

any ~f t is true if the predicate f holds for any element of t

val all : f:('a -> bool) -> 'a t -> bool

all ~f t is true if the predicate f holds for every element of t

val mem : 'a t -> 'a -> equal:('a -> 'a -> bool) -> bool

mem t x ~equal is true if there's an element y in t such that equal x t is true

val max : compare:('a -> 'a -> int) -> 'a t -> 'a option

max ~compare t is Some x when x is the maximum value in t, as determined by compare, or None if is_empty t.

val min : compare:('a -> 'a -> int) -> 'a t -> 'a option

min ~compare t is Some x when m is the minimum value in t, as determined by compare, or None if is_empty t.

OCaml

Innovation. Community. Security.