package mopsa

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

ListExt - Adds a few useful functions to OCaml lists

Import everything from List

include module type of struct include Stdlib.List end
type !'a t = 'a list =
  1. | []
  2. | :: of 'a * 'a list
val length : 'a list -> int
val compare_lengths : 'a list -> 'b list -> int
val compare_length_with : 'a list -> int -> int
val is_empty : 'a list -> bool
val cons : 'a -> 'a list -> 'a list
val hd : 'a list -> 'a
val tl : 'a list -> 'a list
val nth : 'a list -> int -> 'a
val nth_opt : 'a list -> int -> 'a option
val rev : 'a list -> 'a list
val init : int -> (int -> 'a) -> 'a list
val append : 'a list -> 'a list -> 'a list
val rev_append : 'a list -> 'a list -> 'a list
val concat : 'a list list -> 'a list
val flatten : 'a list list -> 'a list
val equal : ('a -> 'a -> bool) -> 'a list -> 'a list -> bool
val iter : ('a -> unit) -> 'a list -> unit
val iteri : (int -> 'a -> unit) -> 'a list -> unit
val map : ('a -> 'b) -> 'a list -> 'b list
val mapi : (int -> 'a -> 'b) -> 'a list -> 'b list
val rev_map : ('a -> 'b) -> 'a list -> 'b list
val filter_map : ('a -> 'b option) -> 'a list -> 'b list
val concat_map : ('a -> 'b list) -> 'a list -> 'b list
val fold_left_map : ('acc -> 'a -> 'acc * 'b) -> 'acc -> 'a list -> 'acc * 'b list
val fold_left : ('acc -> 'a -> 'acc) -> 'acc -> 'a list -> 'acc
val fold_right : ('a -> 'acc -> 'acc) -> 'a list -> 'acc -> 'acc
val iter2 : ('a -> 'b -> unit) -> 'a list -> 'b list -> unit
val map2 : ('a -> 'b -> 'c) -> 'a list -> 'b list -> 'c list
val rev_map2 : ('a -> 'b -> 'c) -> 'a list -> 'b list -> 'c list
val fold_left2 : ('acc -> 'a -> 'b -> 'acc) -> 'acc -> 'a list -> 'b list -> 'acc
val fold_right2 : ('a -> 'b -> 'acc -> 'acc) -> 'a list -> 'b list -> 'acc -> 'acc
val for_all : ('a -> bool) -> 'a list -> bool
val exists : ('a -> bool) -> 'a list -> bool
val for_all2 : ('a -> 'b -> bool) -> 'a list -> 'b list -> bool
val exists2 : ('a -> 'b -> bool) -> 'a list -> 'b list -> bool
val mem : 'a -> 'a list -> bool
val memq : 'a -> 'a list -> bool
val find : ('a -> bool) -> 'a list -> 'a
val find_opt : ('a -> bool) -> 'a list -> 'a option
val find_index : ('a -> bool) -> 'a list -> int option
val find_map : ('a -> 'b option) -> 'a list -> 'b option
val find_mapi : (int -> 'a -> 'b option) -> 'a list -> 'b option
val filter : ('a -> bool) -> 'a list -> 'a list
val find_all : ('a -> bool) -> 'a list -> 'a list
val filteri : (int -> 'a -> bool) -> 'a list -> 'a list
val partition : ('a -> bool) -> 'a list -> 'a list * 'a list
val partition_map : ('a -> ('b, 'c) Stdlib.Either.t) -> 'a list -> 'b list * 'c list
val assoc : 'a -> ('a * 'b) list -> 'b
val assoc_opt : 'a -> ('a * 'b) list -> 'b option
val assq : 'a -> ('a * 'b) list -> 'b
val assq_opt : 'a -> ('a * 'b) list -> 'b option
val mem_assoc : 'a -> ('a * 'b) list -> bool
val mem_assq : 'a -> ('a * 'b) list -> bool
val remove_assoc : 'a -> ('a * 'b) list -> ('a * 'b) list
val remove_assq : 'a -> ('a * 'b) list -> ('a * 'b) list
val combine : 'a list -> 'b list -> ('a * 'b) list
val sort : ('a -> 'a -> int) -> 'a list -> 'a list
val stable_sort : ('a -> 'a -> int) -> 'a list -> 'a list
val fast_sort : ('a -> 'a -> int) -> 'a list -> 'a list
val sort_uniq : ('a -> 'a -> int) -> 'a list -> 'a list
val merge : ('a -> 'a -> int) -> 'a list -> 'a list -> 'a list
val to_seq : 'a list -> 'a Stdlib.Seq.t
val of_seq : 'a Stdlib.Seq.t -> 'a list

Operations

val last : 'a t -> 'a

Last eleemnt of a list. Raises invalid_arg if the list is empty.

val map_tail : ('a -> 'b) -> 'a list -> 'b list

Tail-recursive version of map. Useful for large lists.

val append_tail : 'a list -> 'a list -> 'a list

Tail-recursive version of append. Useful if the first list is large..

val map_merge : ('a -> 'b list) -> 'a list -> 'b list

Maps e1;e2;...;en to (f e1)@(f e2)@...@(f en)

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

Applies f to every element of the list and kepp only those that return some value. The order of the argument list is preserved.

val split : 'a list -> 'a list * 'a list

split l cuts the list l into two halves. Either the two halves have the same size, or the first list is one element larger. If a,b = split l, then l = a @ b.

Printing

type list_printer = {
  1. print_empty : string;
    (*

    Special text for empty lists

    *)
  2. print_begin : string;
    (*

    Text before the first element.

    *)
  3. print_sep : string;
    (*

    Text between two elements

    *)
  4. print_end : string;
    (*

    Text after the last element

    *)
}

Tells how to print a list.

val printer_plain : list_printer

Print as a space-sparated list, no delimiters.

val printer_list : list_printer

Print as OCaml list: a;b;c.

val printer_tuple : list_printer

Print as OCaml tuple: (a,b,c).

val printer_set : list_printer

Print as set: a;b;c.

val print_gen : ('a -> string -> 'b) -> list_printer -> ('a -> 'c -> unit) -> 'a -> 'c t -> 'b
val print : list_printer -> (Stdlib.out_channel -> 'a -> unit) -> Stdlib.out_channel -> 'a t -> unit
val bprint : list_printer -> (Stdlib.Buffer.t -> 'a -> unit) -> Stdlib.Buffer.t -> 'a t -> unit
val fprint : list_printer -> (Stdlib.Format.formatter -> 'a -> unit) -> Stdlib.Format.formatter -> 'a t -> unit
val to_string : list_printer -> ('a -> unit) -> 'a t -> string
val compare : ('a -> 'b -> int) -> 'a t -> 'b t -> int
val mem_compare : ('a -> 'b -> int) -> 'b -> 'a t -> bool

Parallel functions

As List.iter, but in parallel using nb_threads threads. As threads are used, this only makes sense if the iterated function calls a C function that temporarily lifts the global interpreter lock (e.g., the Clang parser)

OCaml

Innovation. Community. Security.