non_empty_list

A non empty list library for OCaml
README

A list that is known, statically, to be nonempty.
The hd and tl functions don't require option types, or exceptions, improving safety.

This library follows closely Janestreet's Base library,
providing similar complexity and functions to Base.List.

Usage

open Non_empty_list;;

let one = [1];;
val one : int non_empty_list = (::) (1, []) (* [1] *)

let two = cons 2 one;;
val two : int non_empty_list = (::) (2, [1]) (* [2; 1] *)

hd one;;
- : int = 1

append one two;;
- : int non_empty_list = (::) (1, [2; 1]) (* [1; 2; 1] *)

length two;;
- : int = 2

to_list two;;
- : int list = [2; 1]

mem ~equal:( = ) two 2;;
- : bool = true

reduce ~f:( + ) two;;
- : int = 3

Testing

dune build
dune runtest
Install
Published
10 Jul 2021
Maintainers
Sources
non_empty_list-0.1.tbz
sha256=af4bf61dc1beb8b5428955bff3a209a3c231fe93eaa02a70cbb13907bb65a85b
sha512=be98fd76da87c1b40452b970c9b9826d5ba16a0629e46f67230b654c8d5b954b12082ecfec68594abf6440fb531599972dc579537c0149801de86cd84f4c99f8
Dependencies
alcotest
with-test
base
>= "v0.14.1"
dune
>= "2.8"
ocaml
>= "4.08.0"
Reverse Dependencies