/Prelude-v23.0.0/NonEmpty/last.dhall

Copy path to clipboard

Retrieve the last element of the NonEmpty list

Examples

last Natural { head = 0, tail = [ 1, 2 ] } ≡ 2
last Natural { head = 0, tail = [] : List Natural } ≡ 0

Source

--| Retrieve the last element of the `NonEmpty` list
let NonEmpty =
missing sha256:e2e247455a858317e470e0e4affca8ac07f9f130570ece9cb7ac1f4ea3deb87f
? ./Type.dhall

let last
: ∀(a : Type) → NonEmpty a → a
= λ(a : Type) →
λ(xs : NonEmpty a) →
merge { Some = λ(x : a) → x, None = xs.head } (List/last a xs.tail)

let example0 = assert : last Natural { head = 0, tail = [ 1, 2 ] } ≡ 2

let example1 = assert : last Natural { head = 0, tail = [] : List Natural } ≡ 0

in last