Skip to content

last

Module Export

[value] |> value | nothing

Returns the last element in the input iterator.

If the iterator is empty, nothing is returned.

Examples

Basic usage

import 'iterators'
from [1, 2, 3] last

Result:

3

Combined with select

import 'iterators'
from
[1, 2, 3]
select x => x * 2
last

Result:

6

Combined with until for early termination

import 'iterators'
let Error: { error: text }
let results = [
{ value = 1 },
{ value = 2 },
{ error = 'something went wrong' }
]
from
results
until r => r is Error
last

Result:

{ error = 'something went wrong' }