Module CCList

module CCList: sig .. end

complements to list



type 'a t = 'a list 
val empty : 'a t
val is_empty : 'a t -> bool
is_empty l returns true iff l = []
Since 0.11
val map : ('a -> 'b) -> 'a t -> 'b t
Safe version of map
val (>|=) : 'a t -> ('a -> 'b) -> 'b t
Infix version of map with reversed arguments
Since 0.5
val cons : 'a -> 'a t -> 'a t
cons x l is x::l
Since 0.12
val append : 'a t -> 'a t -> 'a t
Safe version of append
val cons_maybe : 'a option -> 'a t -> 'a t
cons_maybe (Some x) l is x :: l cons_maybe None l is l
Since 0.13
val (@) : 'a t -> 'a t -> 'a t
val filter : ('a -> bool) -> 'a t -> 'a t
Safe version of List.filter
val fold_right : ('a -> 'b -> 'b) -> 'a t -> 'b -> 'b
Safe version of fold_right
val fold_while : ('a -> 'b -> 'a * [ `Continue | `Stop ]) -> 'a -> 'b t -> 'a
Fold until a stop condition via ('a, `Stop) is indicated by the accumulator
Since 0.8
val fold_map : ('acc -> 'a -> 'acc * 'b) -> 'acc -> 'a list -> 'acc * 'b list
fold_map f acc l is a fold_left-like function, but it also maps the list to another list.
Since 0.14
val fold_map2 : ('acc -> 'a -> 'b -> 'acc * 'c) ->
'acc -> 'a list -> 'b list -> 'acc * 'c list
fold_map2 is to fold_map what List.map2 is to List.map.
Since 0.16
Raises Invalid_argument if the lists do not have the same length
val fold_filter_map : ('acc -> 'a -> 'acc * 'b option) -> 'acc -> 'a list -> 'acc * 'b list
fold_filter_map f acc l is a fold_left-like function, but also generates a list of output in a way similar to CCList.filter_map
Since 0.17
val fold_flat_map : ('acc -> 'a -> 'acc * 'b list) -> 'acc -> 'a list -> 'acc * 'b list
fold_flat_map f acc l is a fold_left-like function, but it also maps the list to a list of lists that is then flatten'd..
Since 0.14
val init : int -> (int -> 'a) -> 'a t
Similar to Array.init
Since 0.6
val compare : ('a -> 'a -> int) -> 'a t -> 'a t -> int
val equal : ('a -> 'a -> bool) -> 'a t -> 'a t -> bool
val flat_map : ('a -> 'b t) -> 'a t -> 'b t
Map and flatten at the same time (safe). Evaluation order is not guaranteed.
val flatten : 'a t t -> 'a t
Safe flatten
val product : ('a -> 'b -> 'c) -> 'a t -> 'b t -> 'c t
Cartesian product of the two lists, with the given combinator
val fold_product : ('c -> 'a -> 'b -> 'c) -> 'c -> 'a t -> 'b t -> 'c
Fold on the cartesian product
val diagonal : 'a t -> ('a * 'a) t
All pairs of distinct positions of the list. list_diagonal l will return the list of List.nth i l, List.nth j l if i < j.
val partition_map : ('a -> [< `Drop | `Left of 'b | `Right of 'c ]) ->
'a list -> 'b list * 'c list
partition_map f l maps f on l and gather results in lists:
Since 0.11
val pure : 'a -> 'a t
val (<*>) : ('a -> 'b) t -> 'a t -> 'b t
val (<$>) : ('a -> 'b) -> 'a t -> 'b t
val return : 'a -> 'a t
val (>>=) : 'a t -> ('a -> 'b t) -> 'b t
val take : int -> 'a t -> 'a t
Take the n first elements, drop the rest
val drop : int -> 'a t -> 'a t
Drop the n first elements, keep the rest
val hd_tl : 'a t -> 'a * 'a t
hd_tl (x :: l) returns hd, l.
Since 0.16
Raises Failure if the list is empty
val take_drop : int -> 'a t -> 'a t * 'a t
take_drop n l returns l1, l2 such that l1 @ l2 = l and length l1 = min (length l) n
val take_while : ('a -> bool) -> 'a t -> 'a t
Since 0.13
val drop_while : ('a -> bool) -> 'a t -> 'a t
Since 0.13
val split : int -> 'a t -> 'a t * 'a t
Deprecated.since 0.13: conflict with the List.split standard function
Synonym to CCList.take_drop
val last : int -> 'a t -> 'a t
last n l takes the last n elements of l (or less if l doesn't have that many elements
val find_pred : ('a -> bool) -> 'a t -> 'a option
find_pred p l finds the first element of l that satisfies p, or returns None if no element satisfies p
Since 0.11
val find_pred_exn : ('a -> bool) -> 'a t -> 'a
Unsafe version of CCList.find_pred
Since 0.11
Raises Not_found if no such element is found
val find_map : ('a -> 'b option) -> 'a t -> 'b option
find_map f l traverses l, applying f to each element. If for some element x, f x = Some y, then Some y is returned. Otherwise the call returns None
Since 0.11
val find : ('a -> 'b option) -> 'a list -> 'b option
Deprecated.since 0.11 in favor of CCList.find_map, for the name is too confusing
val find_mapi : (int -> 'a -> 'b option) -> 'a t -> 'b option
Like CCList.find_map, but also pass the index to the predicate function.
Since 0.11
val findi : (int -> 'a -> 'b option) -> 'a t -> 'b option
Deprecated.since 0.11 in favor of CCList.find_mapi, name is too confusing
Since 0.3.4
val find_idx : ('a -> bool) -> 'a t -> (int * 'a) option
find_idx p x returns Some (i,x) where x is the i-th element of l, and p x holds. Otherwise returns None
val remove : ?eq:('a -> 'a -> bool) -> x:'a -> 'a t -> 'a t
remove ~x l removes every instance of x from l. Tailrec.
Since 0.11
eq : equality function
val filter_map : ('a -> 'b option) -> 'a t -> 'b t
Map and remove elements at the same time
val sorted_merge : ?cmp:('a -> 'a -> int) -> 'a list -> 'a list -> 'a list
Merges elements from both sorted list
val sort_uniq : ?cmp:('a -> 'a -> int) -> 'a list -> 'a list
Sort the list and remove duplicate elements
val sorted_merge_uniq : ?cmp:('a -> 'a -> int) -> 'a list -> 'a list -> 'a list
sorted_merge_uniq l1 l2 merges the sorted lists l1 and l2 and removes duplicates
Since 0.10
val is_sorted : ?cmp:('a -> 'a -> int) -> 'a list -> bool
is_sorted l returns true iff l is sorted (according to given order)
Since 0.17
cmp : the comparison function (default Pervasives.compare)
val sorted_insert : ?cmp:('a -> 'a -> int) -> ?uniq:bool -> 'a -> 'a list -> 'a list
sorted_insert x l inserts x into l such that, if l was sorted, then sorted_insert x l is sorted too.
Since 0.17
uniq : if true and x is already in sorted position in l, then x is not duplicated. Default false (x will be inserted in any case).
val uniq_succ : ?eq:('a -> 'a -> bool) -> 'a list -> 'a list
uniq_succ l removes duplicate elements that occur one next to the other. Examples: uniq_succ [1;2;1] = [1;2;1] uniq_succ [1;1;2] = [1;2]
Since 0.10
val group_succ : ?eq:('a -> 'a -> bool) -> 'a list -> 'a list list
group_succ ~eq l groups together consecutive elements that are equal according to eq
Since 0.11

Indices


module Idx: sig .. end

Set Operators


module Set: sig .. end

Other Constructors


val range_by : step:int -> int -> int -> int t
range_by ~step i j iterates on integers from i to j included, where the difference between successive elements is step. use a negative step for a decreasing list.
Since 0.18
Raises Invalid_argument if step=0
val range : int -> int -> int t
range i j iterates on integers from i to j included . It works both for decreasing and increasing ranges
val range' : int -> int -> int t
Same as CCList.range but the second bound is excluded. For instance range' 0 5 = [0;1;2;3;4]
val (--) : int -> int -> int t
Infix alias for range
val (--^) : int -> int -> int t
Infix alias for range'
Since 0.17
val replicate : int -> 'a -> 'a t
Replicate the given element n times
val repeat : int -> 'a t -> 'a t
Concatenate the list with itself n times

Association Lists


module Assoc: sig .. end

Zipper


module Zipper: sig .. end

References on Lists


module Ref: sig .. end
module type MONAD = sig .. end
Monadic Operations
module Traverse (M : MONAD) : sig .. end

Conversions


type 'a sequence = ('a -> unit) -> unit 
type 'a gen = unit -> 'a option 
type 'a klist = unit -> [ `Cons of 'a * 'a klist | `Nil ] 
type 'a printer = Buffer.t -> 'a -> unit 
type 'a formatter = Format.formatter -> 'a -> unit 
type 'a random_gen = Random.State.t -> 'a 
val random : 'a random_gen -> 'a t random_gen
val random_non_empty : 'a random_gen -> 'a t random_gen
val random_len : int -> 'a random_gen -> 'a t random_gen
val random_choose : 'a t -> 'a random_gen
Randomly choose an element in the list.
Raises Not_found if the list is empty
val random_sequence : 'a random_gen t -> 'a t random_gen
val to_seq : 'a t -> 'a sequence
val of_seq : 'a sequence -> 'a t
val to_gen : 'a t -> 'a gen
val of_gen : 'a gen -> 'a t
val to_klist : 'a t -> 'a klist
val of_klist : 'a klist -> 'a t

Infix Operators

It is convenient to open CCList.Infix to access the infix operators without cluttering the scope too much.
module Infix: sig .. end

IO


val pp : ?start:string ->
?stop:string ->
?sep:string -> 'a printer -> 'a t printer
val print : ?start:string ->
?stop:string ->
?sep:string -> 'a formatter -> 'a t formatter