package preface

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

Implementation for Nonempty_list.t.

A Nonempty_list.t is a list that contains at least one element. Therefore, the head and tails functions are total and safe.

Type

type 'a t = 'a Preface_core.Nonempty_list.t =
  1. | Last of 'a
  2. | :: of 'a * 'a t

Implementation

Functor

module Functor : Preface_specs.FUNCTOR with type 'a t = 'a t

Alt

module Alt : Preface_specs.ALT with type 'a t = 'a t

Applicative

Nonempty_list.t implements Preface_specs.APPLICATIVE and introduces an interface to define Preface_specs.TRAVERSABLE using Nonempty_list as an iterable structure.

Selective

module Selective : Preface_specs.SELECTIVE with type 'a t = 'a t

Monad

Nonempty_list.t implements Preface_specs.MONAD and introduces an interface to define Preface_specs.TRAVERSABLE using Nonempty_list as an iterable structure.

Comonad

module Comonad : Preface_specs.COMONAD with type 'a t = 'a t

Foldable

module Foldable : Preface_specs.FOLDABLE with type 'a t = 'a t

Invariant Functor

module Invariant : Preface_specs.INVARIANT with type 'a t = 'a t

Delayed implementation

By setting the inner type type of Nonempty_list.t it is possible to get implementations for abstractions without type parameter.

Semigroup

Additional functions

Additional functions to facilitate practical work with Nonempty_list.t.

val pure : 'a -> 'a t

Create a value from 'a to 'a t.

val create : 'a -> 'a t

create x create a new non-empty list with x.

val from_list : 'a list -> 'a t option

Creates a non-empty list from a regular list.

val to_list : 'a t -> 'a list

Convert non-empty list to a regular list.

val hd : 'a t -> 'a

Returns the head of a non-empty list.

val tl : 'a t -> 'a t option

Returns the tail of a non-empty list.

val length : 'a t -> int

Returns the length of a non-empty list.

val cons : 'a -> 'a t -> 'a t

cons x xs is add x as head of xs.

val append : 'a t -> 'a t -> 'a t

append a b concat a and b.

val rev : 'a t -> 'a t

rev xs reverse xs.

val rev_append : 'a t -> 'a t -> 'a t

rev_append a b is a tail-recursive version of append (rev a) b.

val flatten : 'a t t -> 'a t

Concat a non-empty list of non-empty list

val iter : ('a -> unit) -> 'a t -> unit

List.iter for non-empty list.

val iteri : (int -> 'a -> unit) -> 'a t -> unit

List.iteri for non-empty list.

val map : ('a -> 'b) -> 'a t -> 'b t

List.map for non-empty list.

val mapi : (int -> 'a -> 'b) -> 'a t -> 'b t

List.mapi for non-empty list.

val reduce : ('a -> 'a -> 'a) -> 'a t -> 'a

reduce f xs reduce all value of xs into one.

val fold_left : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'a

List.fold_left for non-empty list.

val fold_right : ('a -> 'b -> 'b) -> 'a t -> 'b -> 'b

List.fold_right for non-empty list.

val equal : ('a -> 'a -> bool) -> 'a t -> 'a t -> bool

Equality between Nonempty_list.t.

val pp : (Stdlib.Format.formatter -> 'a -> unit) -> Stdlib.Format.formatter -> 'a t -> unit

Formatter for pretty-printing for Nonempty_list.t.