package containers

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module CCSeqSource

Helpers for the standard Seq type

See oseq for a richer API.

Sourcetype 'a iter = ('a -> unit) -> unit
Sourcetype 'a gen = unit -> 'a option
Sourcetype 'a equal = 'a -> 'a -> bool
Sourcetype 'a ord = 'a -> 'a -> int
Sourcetype 'a printer = Format.formatter -> 'a -> unit

Basics

Sourcetype +'a t = unit -> 'a node
Sourceand +'a node = 'a Seq.node =
  1. | Nil
  2. | Cons of 'a * 'a t
Sourceval nil : 'a t
Sourceval empty : 'a t
Sourceval cons : 'a -> 'a t -> 'a t
Sourceval singleton : 'a -> 'a t
Sourceval repeat : ?n:int -> 'a -> 'a t

repeat ~n x repeats x n times then stops. If n is omitted, then x is repeated forever.

  • since 0.3.3
Sourceval cycle : 'a t -> 'a t

Cycle through the iterator infinitely. The iterator shouldn't be empty.

  • since 0.3.3
Sourceval unfold : ('b -> ('a * 'b) option) -> 'b -> 'a t

unfold f acc calls f acc and:

  • if f acc = Some (x, acc'), yield x, continue with unfold f acc'.
  • if f acc = None, stops.
  • since 0.13
Sourceval is_empty : 'a t -> bool
Sourceval head : 'a t -> 'a option

Head of the list.

  • since 0.13
Sourceval head_exn : 'a t -> 'a

Unsafe version of head.

  • since 0.13
Sourceval tail : 'a t -> 'a t option

Tail of the list.

  • since 0.13
Sourceval tail_exn : 'a t -> 'a t

Unsafe version of tail.

  • since 0.13
Sourceval equal : 'a equal -> 'a t equal

Equality step by step. Eager.

Sourceval compare : 'a ord -> 'a t ord

Lexicographic comparison. Eager.

Sourceval fold : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'a

Fold on values.

Sourceval fold_left : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'a

Alias for fold

Sourceval iter : ('a -> unit) -> 'a t -> unit
Sourceval iteri : (int -> 'a -> unit) -> 'a t -> unit

Iterate with index (starts at 0).

  • since 0.13
Sourceval length : _ t -> int

Number of elements in the list. Will not terminate if the list if infinite: use (for instance) take to make the list finite if necessary.

Sourceval take : int -> 'a t -> 'a t
Sourceval take_while : ('a -> bool) -> 'a t -> 'a t
Sourceval drop : int -> 'a t -> 'a t
Sourceval drop_while : ('a -> bool) -> 'a t -> 'a t
Sourceval map : ('a -> 'b) -> 'a t -> 'b t
Sourceval mapi : (int -> 'a -> 'b) -> 'a t -> 'b t

Map with index (starts at 0).

  • since 0.13
Sourceval fmap : ('a -> 'b option) -> 'a t -> 'b t
Sourceval filter : ('a -> bool) -> 'a t -> 'a t
Sourceval append : 'a t -> 'a t -> 'a t
Sourceval product_with : ('a -> 'b -> 'c) -> 'a t -> 'b t -> 'c t

Fair product of two (possibly infinite) lists into a new list. Lazy. The first parameter is used to combine each pair of elements.

  • since 0.3.3
Sourceval product : 'a t -> 'b t -> ('a * 'b) t

Specialization of product_with producing tuples.

  • since 0.3.3
Sourceval group : 'a equal -> 'a t -> 'a t t

group eq l groups together consecutive elements that satisfy eq. Lazy. For instance group (=) [1;1;1;2;2;3;3;1] yields [1;1;1]; [2;2]; [3;3]; [1].

  • since 0.3.3
Sourceval uniq : 'a equal -> 'a t -> 'a t

uniq eq l returns l but removes consecutive duplicates. Lazy. In other words, if several values that are equal follow one another, only the first of them is kept.

  • since 0.3.3
Sourceval flat_map : ('a -> 'b t) -> 'a t -> 'b t
Sourceval filter_map : ('a -> 'b option) -> 'a t -> 'b t
Sourceval flatten : 'a t t -> 'a t
Sourceval range : int -> int -> int t
Sourceval (--) : int -> int -> int t

a -- b is the range of integers containing a and b (therefore, never empty).

Sourceval (--^) : int -> int -> int t

a -- b is the integer range from a to b, where b is excluded.

  • since 0.17

Operations on two Collections

Sourceval fold2 : ('acc -> 'a -> 'b -> 'acc) -> 'acc -> 'a t -> 'b t -> 'acc

Fold on two collections at once. Stop at soon as one of them ends.

Sourceval map2 : ('a -> 'b -> 'c) -> 'a t -> 'b t -> 'c t

Map on two collections at once. Stop as soon as one of the arguments is exhausted.

Sourceval iter2 : ('a -> 'b -> unit) -> 'a t -> 'b t -> unit

Iterate on two collections at once. Stop as soon as one of them ends.

Sourceval for_all2 : ('a -> 'b -> bool) -> 'a t -> 'b t -> bool
Sourceval exists2 : ('a -> 'b -> bool) -> 'a t -> 'b t -> bool
Sourceval merge : 'a ord -> 'a t -> 'a t -> 'a t

Merge two sorted iterators into a sorted iterator.

Sourceval zip : 'a t -> 'b t -> ('a * 'b) t

Combine elements pairwise. Stop as soon as one of the lists stops.

  • since 0.13
Sourceval unzip : ('a * 'b) t -> 'a t * 'b t

Split each tuple in the list.

  • since 0.13

Misc

Sourceval sort : cmp:'a ord -> 'a t -> 'a t

Eager sort. Require the iterator to be finite. O(n ln(n)) time and space.

  • since 0.3.3
Sourceval sort_uniq : cmp:'a ord -> 'a t -> 'a t

Eager sort that removes duplicate values. Require the iterator to be finite. O(n ln(n)) time and space.

  • since 0.3.3
Sourceval memoize : 'a t -> 'a t

Avoid recomputations by caching intermediate results.

  • since 0.14

Fair Combinations

Sourceval interleave : 'a t -> 'a t -> 'a t

Fair interleaving of both streams.

  • since 0.13
Sourceval fair_flat_map : ('a -> 'b t) -> 'a t -> 'b t

Fair version of flat_map.

  • since 0.13
Sourceval fair_app : ('a -> 'b) t -> 'a t -> 'b t

Fair version of (<*>).

  • since 0.13

Implementations

  • since 0.3.3
Sourceval return : 'a -> 'a t
Sourceval pure : 'a -> 'a t
Sourceval (>>=) : 'a t -> ('a -> 'b t) -> 'b t
Sourceval (>|=) : 'a t -> ('a -> 'b) -> 'b t
Sourceval (<*>) : ('a -> 'b) t -> 'a t -> 'b t
Sourceval (>>-) : 'a t -> ('a -> 'b t) -> 'b t

Infix version of fair_flat_map.

  • since 0.13
Sourceval (<.>) : ('a -> 'b) t -> 'a t -> 'b t

Infix version of fair_app.

  • since 0.13

Infix operators

  • since 0.17
Sourcemodule Infix : sig ... end
Sourcemodule type MONAD = sig ... end
Sourcemodule Traverse (M : MONAD) : sig ... end

Conversions

Sourceval of_list : 'a list -> 'a t
Sourceval to_list : 'a t -> 'a list

Gather all values into a list.

Sourceval of_array : 'a array -> 'a t

Iterate on the array.

  • since 0.13
Sourceval to_array : 'a t -> 'a array

Convert into array. Iterate twice.

  • since 0.13
Sourceval to_rev_list : 'a t -> 'a list

Convert to a list, in reverse order. More efficient than to_list.

Sourceval to_iter : 'a t -> 'a iter
Sourceval to_gen : 'a t -> 'a gen
Sourceval of_gen : 'a gen -> 'a t

of_gen g consumes the generator and caches intermediate results.

  • since 0.13

IO

Sourceval pp : ?pp_start:unit printer -> ?pp_stop:unit printer -> ?pp_sep:unit printer -> 'a printer -> 'a t printer

pp ~pp_start ~pp_stop ~pp_sep pp_item ppf s formats the sequence s on ppf. Each element is formatted with pp_item, pp_start is called at the beginning, pp_stop is called at the end, pp_sep is called between each elements. By defaults pp_start and pp_stop does nothing and pp_sep defaults to (fun out -> Format.fprintf out ",@ ").

OCaml

Innovation. Community. Security.