package containers

  1. Overview
  2. Docs
A modular, clean and powerful extension of the OCaml standard library

Install

Dune Dependency

Authors

Maintainers

Sources

v2.8.1.tar.gz
md5=d84e09c5d0abc501aa17cd502e31a038
sha512=8b832f4ada6035e80d81be0cfb7bdffb695ec67d465ed6097a144019e2b8a8f909095e78019c3da2d8181cc3cd730cd48f7519e87d3162442562103b7f36aabb

doc/containers.data/CCFQueue/index.html

Module CCFQueueSource

Functional queues

Sourcetype 'a sequence = ('a -> unit) -> unit
Sourcetype 'a klist = unit -> [ `Nil | `Cons of 'a * 'a klist ]
Sourcetype 'a equal = 'a -> 'a -> bool
Sourcetype 'a printer = Format.formatter -> 'a -> unit

Basics

Sourcetype +'a t

Queue containing elements of type 'a

Sourceval empty : 'a t
Sourceval is_empty : 'a t -> bool
Sourceval singleton : 'a -> 'a t
Sourceval doubleton : 'a -> 'a -> 'a t
Sourceexception Empty
Sourceval cons : 'a -> 'a t -> 'a t

Push element at the front of the queue.

Sourceval snoc : 'a t -> 'a -> 'a t

Push element at the end of the queue.

Sourceval take_front : 'a t -> ('a * 'a t) option

Get and remove the first element.

Sourceval take_front_exn : 'a t -> 'a * 'a t

Same as take_front, but fails on empty queues.

  • raises Empty

    if the queue is empty.

Sourceval take_front_l : int -> 'a t -> 'a list * 'a t

take_front_l n q takes at most n elements from the front of q, and returns them wrapped in a list.

Sourceval take_front_while : ('a -> bool) -> 'a t -> 'a list * 'a t
Sourceval take_back : 'a t -> ('a t * 'a) option

Take last element.

Sourceval take_back_exn : 'a t -> 'a t * 'a

Same as take_back, but fails on empty queues.

  • raises Empty

    if the queue is empty.

Sourceval take_back_l : int -> 'a t -> 'a t * 'a list

take_back_l n q removes and returns the last n elements of q. The elements are in the order of the queue, that is, the head of the returned list is the first element to appear via take_front. take_back_l 2 (of_list [1;2;3;4]) = of_list [1;2], [3;4].

Sourceval take_back_while : ('a -> bool) -> 'a t -> 'a t * 'a list

Individual extraction

Sourceval first : 'a t -> 'a option

First element of the queue.

Sourceval last : 'a t -> 'a option

Last element of the queue.

Sourceval first_exn : 'a t -> 'a

Same as first but

  • raises Empty

    if the queue is empty.

Sourceval last_exn : 'a t -> 'a
Sourceval nth : int -> 'a t -> 'a option

Return the i-th element of the queue in logarithmic time.

Sourceval nth_exn : int -> 'a t -> 'a

Unsafe version of nth.

Sourceval tail : 'a t -> 'a t

Queue deprived of its first element. Does nothing on empty queues.

Sourceval init : 'a t -> 'a t

Queue deprived of its last element. Does nothing on empty queues.

Global Operations

Sourceval append : 'a t -> 'a t -> 'a t

Append two queues. Elements from the second one come after elements of the first one. Linear in the size of the second queue.

Sourceval rev : 'a t -> 'a t

Reverse the queue, O(n) complexity.

  • since 0.10
Sourceval map : ('a -> 'b) -> 'a t -> 'b t

Map values.

Sourceval (>|=) : 'a t -> ('a -> 'b) -> 'b t

Synonym to map.

Sourceval size : 'a t -> int

Number of elements in the queue (constant time).

Sourceval fold : ('b -> 'a -> 'b) -> 'b -> 'a t -> 'b
Sourceval iter : ('a -> unit) -> 'a t -> unit
Sourceval equal : 'a equal -> 'a t equal

Conversions

Sourceval of_list : 'a list -> 'a t
Sourceval to_list : 'a t -> 'a list
Sourceval add_seq_front : 'a sequence -> 'a t -> 'a t
Sourceval add_seq_back : 'a t -> 'a sequence -> 'a t
Sourceval to_seq : 'a t -> 'a sequence
Sourceval of_seq : 'a sequence -> 'a t
Sourceval to_klist : 'a t -> 'a klist
Sourceval of_klist : 'a klist -> 'a t
Sourceval (--) : int -> int -> int t

a -- b is the integer range from a to b, both included.

  • since 0.10
Sourceval (--^) : int -> int -> int t

a -- b is the integer range from a to b, where b is excluded.

  • since 0.17
Sourceval pp : 'a printer -> 'a t printer
  • since 0.13
OCaml

Innovation. Community. Security.