Module CCKList
Continuation List
- deprecated
since 2.7, you should use the standard Seq instead. See oseq for similar combinators.
type 'a sequence= ('a -> unit) -> unittype 'a gen= unit -> 'a optiontype 'a equal= 'a -> 'a -> booltype 'a ord= 'a -> 'a -> inttype 'a printer= Format.formatter -> 'a -> unit
Basics
type +'a t= unit -> [ `Nil | `Cons of 'a * 'a t ]
val nil : 'a tval empty : 'a tval cons : 'a -> 'a t -> 'a tval singleton : 'a -> 'a tval repeat : ?n:int -> 'a -> 'a trepeat ~n xrepeatsxntimes then stops. Ifnis omitted, thenxis repeated forever.- since
- 0.3.3
val cycle : 'a t -> 'a tCycle through the iterator infinitely. The iterator shouldn't be empty.
- since
- 0.3.3
val unfold : ('b -> ('a * 'b) option) -> 'b -> 'a tunfold f acccallsf accand:- if
f acc = Some (x, acc'), yieldx, continue withunfold f acc'. - if
f acc = None, stops.
- since
- 0.13
- if
val fold : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'aFold on values.
val iter : ('a -> unit) -> 'a t -> unitval iteri : (int -> 'a -> unit) -> 'a t -> unitIterate with index (starts at 0).
- since
- 0.13
val length : _ t -> intNumber of elements in the list. Will not terminate if the list if infinite: use (for instance)
taketo make the list finite if necessary.
val take : int -> 'a t -> 'a tval take_while : ('a -> bool) -> 'a t -> 'a tval drop : int -> 'a t -> 'a tval drop_while : ('a -> bool) -> 'a t -> 'a tval map : ('a -> 'b) -> 'a t -> 'b tval mapi : (int -> 'a -> 'b) -> 'a t -> 'b tMap with index (starts at 0).
- since
- 0.13
val fmap : ('a -> 'b option) -> 'a t -> 'b tval filter : ('a -> bool) -> 'a t -> 'a tval append : 'a t -> 'a t -> 'a tval product_with : ('a -> 'b -> 'c) -> 'a t -> 'b t -> 'c tFair 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
val product : 'a t -> 'b t -> ('a * 'b) tSpecialization of
product_withproducing tuples.- since
- 0.3.3
val group : 'a equal -> 'a t -> 'a t tgroup eq lgroups together consecutive elements that satisfyeq. Lazy. For instancegroup (=) [1;1;1;2;2;3;3;1]yields[1;1;1]; [2;2]; [3;3]; [1].- since
- 0.3.3
val uniq : 'a equal -> 'a t -> 'a tuniq eq lreturnslbut 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
val flat_map : ('a -> 'b t) -> 'a t -> 'b tval filter_map : ('a -> 'b option) -> 'a t -> 'b tval flatten : 'a t t -> 'a tval range : int -> int -> int tval (--) : int -> int -> int ta -- bis the range of integers containingaandb(therefore, never empty).
val (--^) : int -> int -> int ta -- bis the integer range fromatob, wherebis excluded.- since
- 0.17
Operations on two Collections
val fold2 : ('acc -> 'a -> 'b -> 'acc) -> 'acc -> 'a t -> 'b t -> 'accFold on two collections at once. Stop at soon as one of them ends.
val map2 : ('a -> 'b -> 'c) -> 'a t -> 'b t -> 'c tMap on two collections at once. Stop as soon as one of the arguments is exhausted.
val iter2 : ('a -> 'b -> unit) -> 'a t -> 'b t -> unitIterate on two collections at once. Stop as soon as one of them ends.
val for_all2 : ('a -> 'b -> bool) -> 'a t -> 'b t -> boolval exists2 : ('a -> 'b -> bool) -> 'a t -> 'b t -> boolval merge : 'a ord -> 'a t -> 'a t -> 'a tMerge two sorted iterators into a sorted iterator.
Misc
val sort : cmp:'a ord -> 'a t -> 'a tEager sort. Require the iterator to be finite.
O(n ln(n))time and space.- since
- 0.3.3
Fair Combinations
Implementations
- since
- 0.3.3
Infix operators
- since
- 0.17
module Infix : sig ... endmodule type MONAD = sig ... end
Conversions
val of_array : 'a array -> 'a tIterate on the array.
- since
- 0.13
val to_array : 'a t -> 'a arrayConvert into array. Iterate twice.
- since
- 0.13