package bwd

  1. Overview
  2. Docs

This module is similar to ListLabels but for backward lists.

Notes on the discrepancies with ListLabels:

  • New:

    • prepend was added as the forward version of append.
    • to_list and of_list were added for conversions between standard lists.
    • Infix was added for the infix notation.
  • Changed:

  • Forbidden:

    • Functions rev, rev_append, rev_map, and rev_map2 will never be included.
  • Missing but may be added in the future:

    • tl (as hd for lists), hd (as tl for lists), concat, flatten, concat_map.
    • Functions related to association lists.
    • Functions related to sorting.
    • Conversion from/to sequences.

Please open a GitHub issue if you want a function to be included. We want to make this library useful to you, too!

type 'a t = 'a bwd =
  1. | Emp
  2. | Snoc of 'a bwd * 'a
val length : 'a bwd -> int
val compare_lengths : 'a bwd -> 'a bwd -> int
val compare_length_with : 'a bwd -> len:int -> int
val is_empty : 'a bwd -> bool
val snoc : 'a bwd -> 'a -> 'a bwd
val nth : 'a bwd -> int -> 'a
val nth_opt : 'a bwd -> int -> 'a option
val init : len:int -> f:(int -> 'a) -> 'a bwd
val append : 'a bwd -> 'a list -> 'a bwd
val prepend : 'a bwd -> 'a list -> 'a list

Comparison

val equal : eq:('a -> 'a -> bool) -> 'a bwd -> 'a bwd -> bool
val compare : cmp:('a -> 'a -> int) -> 'a bwd -> 'a bwd -> int

Iterators

Note that the iteration direction is from the right to the left, in the opposite direction of the corresponding functions in ListLabels.

val iter : f:('a -> unit) -> 'a bwd -> unit
val iteri : f:(int -> 'a -> unit) -> 'a bwd -> unit
val map : f:('a -> 'b) -> 'a bwd -> 'b bwd
val mapi : f:(int -> 'a -> 'b) -> 'a bwd -> 'b bwd
val filter_map : f:('a -> 'b option) -> 'a bwd -> 'b bwd
val fold_left : f:('a -> 'b -> 'a) -> init:'a -> 'b bwd -> 'a
val fold_right_map : f:('a -> 'b -> 'b * 'c) -> 'a bwd -> init:'b -> 'b * 'c bwd
val fold_right : f:('a -> 'b -> 'b) -> 'a bwd -> init:'b -> 'b

Iterators on two lists

Note that the iteration direction is from the right to the left, in the opposite direction of the corresponding functions in ListLabels.

val iter2 : f:('a -> 'b -> unit) -> 'a bwd -> 'b bwd -> unit
val map2 : f:('a -> 'b -> 'c) -> 'a bwd -> 'b bwd -> 'c bwd
val fold_left2 : f:('a -> 'b -> 'c -> 'a) -> init:'a -> 'b bwd -> 'c bwd -> 'a
val fold_right2 : f:('a -> 'b -> 'c -> 'c) -> 'a bwd -> 'b bwd -> init:'c -> 'c

List scanning

Note that the iteration direction is from the right to the left, in the opposite direction of the corresponding functions in ListLabels.

val for_all : f:('a -> bool) -> 'a bwd -> bool
val exists : f:('a -> bool) -> 'a bwd -> bool
val for_all2 : f:('a -> 'b -> bool) -> 'a bwd -> 'b bwd -> bool
val exists2 : f:('a -> 'b -> bool) -> 'a bwd -> 'b bwd -> bool
val mem : 'a -> set:'a bwd -> bool
val memq : 'a -> set:'a bwd -> bool

List searching

Note that the iteration direction is from the right to the left, in the opposite direction of the corresponding functions in ListLabels.

val find : f:('a -> bool) -> 'a bwd -> 'a
val find_opt : f:('a -> bool) -> 'a bwd -> 'a option
val find_index : f:('a -> bool) -> 'a bwd -> int option
val find_map : f:('a -> 'b option) -> 'a bwd -> 'b option
val find_mapi : f:(int -> 'a -> 'b option) -> 'a bwd -> 'b option
val filter : f:('a -> bool) -> 'a bwd -> 'a bwd
val find_all : f:('a -> bool) -> 'a bwd -> 'a bwd
val filteri : f:(int -> 'a -> bool) -> 'a bwd -> 'a bwd
val partition : f:('a -> bool) -> 'a bwd -> 'a bwd * 'a bwd
val partition_map : f:('a -> ('b, 'c) Either.t) -> 'a bwd -> 'b bwd * 'c bwd

Lists of pairs

val split : ('a * 'b) bwd -> 'a bwd * 'b bwd
val combine : 'a bwd -> 'b bwd -> ('a * 'b) bwd

Backward and forward lists

val to_list : 'a bwd -> 'a list
val of_list : 'a list -> 'a bwd

Infix notation

module Infix : sig ... end
OCaml

Innovation. Community. Security.