package opam-core

  1. Overview
  2. Docs
val cons : 'a -> 'a list -> 'a list
val concat_map : ?left:string -> ?right:string -> ?nil:string -> ?last_sep:string -> string -> ('a -> string) -> 'a list -> string

Convert list items to string and concat. sconcat_map sep f x is equivalent to String.concat sep (List.map f x) but tail-rec.

val find_opt : ('a -> bool) -> 'a list -> 'a option

Like List.find, but returning option instead of raising

val to_string : ('a -> string) -> 'a list -> string
val remove_duplicates : ('a -> 'a -> bool) -> 'a list -> 'a list

Removes consecutive duplicates in a list

val sort_nodup : ('a -> 'a -> int) -> 'a list -> 'a list

Sorts the list, removing duplicates

val filter_map : ('a -> 'b option) -> 'a list -> 'b list

Filter and map

val filter_some : 'a option list -> 'a list

Retrieves Some values from a list

val find_map : ('a -> 'b option) -> 'a list -> 'b

Returns the first non-None value returned by the passed function on the elements of the passed list.

  • raises Not_found

    if all of them yield None

val find_map_opt : ('a -> 'b option) -> 'a list -> 'b option

Like find_map, but returns Some _ if succeeded and None if failed.

val insert : ('a -> 'a -> int) -> 'a -> 'a list -> 'a list

Insert a value in an ordered list

val insert_at : int -> 'a -> 'a list -> 'a list

Inserts a value at the given index (starting from 0) in the list (start or end if index < 0 or > length respectively). Not tail-recursive

val assoc : ('a -> 'a -> bool) -> 'a -> ('a * 'b) list -> 'b

Like List.assoc with an equality function.

val assoc_opt : ('a -> 'a -> bool) -> 'a -> ('a * 'b) list -> 'b option

Like assoc, but returning option instead of raising Not_found

val pick_assoc : ('a -> 'a -> bool) -> 'a -> ('a * 'b) list -> 'b option * ('a * 'b) list

Like assoc, but as an option, and also returns the list with the binding removed, e.g. equivalent to (assoc_opt x l, remove_assoc x l) (but tail-recursive and more efficient)

val mem_assoc : ('a -> 'a -> bool) -> 'a -> ('a * 'b) list -> bool

Like assoc, but returns a boolean instead of associated value

val remove_assoc : ('a -> 'a -> bool) -> 'a -> ('a * 'b) list -> ('a * 'b) list

remove_assoc eq k l removes first association of k from list l (tail-recursive).

val update_assoc : ('a -> 'a -> bool) -> 'a -> 'b -> ('a * 'b) list -> ('a * 'b) list

update_assoc key value list updates the first value bound to key in the associative list list, or appends (key, value) if the key is not bound.

val pick : ('a -> bool) -> 'a list -> 'a option * 'a list

Like pick_assoc, but with a test function that takes a list element

val fold_left_map : ('s -> 'a -> 's * 'b) -> 's -> 'a list -> 's * 'b list

Like List.fold_left, but also performs List.map at the same time

OCaml

Innovation. Community. Security.