Closed RobinMalfait closed 1 year ago
This PR adds a new at feature as a continuation of the existing PR #25.
at
Returns the value at the given index.
import { pipe, at } from 'lazy-collections' let program = pipe(at(2)) program([1, 2, 3, 4]) // 3
You can also pass a negative index to at to count back from the end of the array or iterator.
Warning: Performance may be degraded because it has to exhaust the full iterator before it can count backwards!
import { pipe, at } from 'lazy-collections' let program = pipe(at(-2)) program([1, 2, 3, 4]) // 3
If a value can not be found at the given index, then undefined will be returned.
undefined
import { pipe, at } from 'lazy-collections' let program = pipe(at(12)) program([1, 2, 3, 4]) // undefined
Closes: #25 Thanks, @AlexVipond!
This PR adds a new
at
feature as a continuation of the existing PR #25.Returns the value at the given index.
You can also pass a negative index to
at
to count back from the end of the array or iterator.If a value can not be found at the given index, then
undefined
will be returned.Closes: #25 Thanks, @AlexVipond!