A type-safe list that contains at least one element.
open FSharpPlus
open FSharpPlus.Data
// you can construct a NonEmptyList by using ofSeq
let list123' = NonEmptyList.create 1 [ 2; 3 ]
// or more idiomatically
let list123 = nelist { 1 ; 2; 3 } // will work in F# version 4.7
let listOne = NonEmptyList.singleton 1
// cons
let list2 = NonEmptyList.cons 100 list123
// append two NonEmptyLists
let list3 = plus list2 (NonEmptyList.singleton 200)
// this can be written as (since list2 is a NonEmptyList):
let list3' = plus list2 (result 200)
// in order to get back to a regular list you can then use toList:
let list4 = toList list3'
let lengthOfList3 = length list3
let headOf3 = list3.Head
let headOf3' = head list3
let tailOf3 = list3.Tail
namespace FSharpPlus
namespace FSharpPlus.Data
val list123': NonEmptyList<int>
Multiple items
module NonEmptyList
from FSharpPlus.Data
<summary>
Basic operations on NonEmptyList
</summary>
--------------------
type NonEmptyList<'t> =
{
Head: 't
Tail: 't list
}
interface NonEmptySeq<'t>
interface IReadOnlyList<'t>
interface IReadOnlyCollection<'t>
interface IEnumerable
interface IEnumerable<'t>
static member (+) : NonEmptyList<'a1> * x: NonEmptyList<'a1> -> NonEmptyList<'a1>
static member (<*>) : f: NonEmptyList<('T -> 'U)> * x: NonEmptyList<'T> -> NonEmptyList<'U>
static member (<.>) : f: NonEmptyList<('T -> 'U)> * x: NonEmptyList<'T> -> NonEmptyList<'U>
static member (=>>) : s: NonEmptyList<'a1> * g: (NonEmptyList<'a1> -> 'b) -> NonEmptyList<'b>
static member (>>=) : NonEmptyList<'a1> * f: ('a1 -> NonEmptyList<'b>) -> NonEmptyList<'b>
...
<summary>
A type-safe list that contains at least one element.
</summary>
val create: x: 'a -> xs: 'a list -> NonEmptyList<'a>
<summary>Builds a non empty list.</summary>
val list123: NonEmptyList<int>
Multiple items
val nelist: NelBuilder
--------------------
type nelist<'t> = NonEmptyList<'t>
<summary>
A type alias for NonEmptyList<'t>
</summary>
val listOne: NonEmptyList<int>
val singleton: x: 'a -> NonEmptyList<'a>
<summary>Builds a non empty list with a single element.</summary>
val list2: NonEmptyList<int>
val cons: e: 'a -> NonEmptyList<'a> -> NonEmptyList<'a>
<summary>
Returns a new NonEmptyList with the element added to the beginning.
</summary>
val list3: NonEmptyList<int>
val plus: x: 'Monoid -> y: 'Monoid -> 'Monoid (requires member ``+``)
<summary>
Combines two monoids in one.
</summary>
<category index="4">Monoid</category>
val list3': NonEmptyList<int>
val result: x: 'T -> 'Functor<'T> (requires member Return)
<summary>
Lifts a value into a Functor. Same as return in Computation Expressions.
</summary>
<category index="2">Applicative</category>
val list4: int list
val toList: source: 'a -> 'T list (requires member ToList)
<summary>Builds a list from the given foldable.</summary>
<category index="11">Foldable</category>
<param name="source">The input foldable.</param>
<returns>The list of foldable elements.</returns>
val lengthOfList3: int
val length: source: 'Foldable<'T> -> int (requires member Length)
<summary>Gets the number of elements in the foldable.</summary>
<category index="11">Foldable</category>
<param name="source">The input foldable.</param>
<returns>The length of the foldable.</returns>
val headOf3: int
NonEmptyList.Head: int
val headOf3': int
val head: source: 'Foldable<'T> -> 'T (requires member Head)
<summary>Gets the first element of the foldable.</summary>
<category index="11">Foldable</category>
<param name="source">The input flodable.</param>
<exception cref="System.ArgumentException">Thrown when the foldable is empty.</exception>
<returns>The first element of the foldable.</returns>
val tailOf3: int list
NonEmptyList.Tail: int list