Module ddash.range.nth

Gets the element at index n of a range

Example

import ddash.utils.optional: some, none;
import ddash.range: frontOr;
assert([1, 2].nth(1).frontOr(1) == 2);
assert((int[]).init.nth(1).frontOr(9) == 9);

assert([1, 2].nth(1) == some(2));
assert((int[]).init.nth(1) == none);

assert([1, 2, 3].nth!(Yes.wrap)(10) == some(2));

Functions

NameDescription
nth(range, n) Gets the element at index n of array if found, else none.

Aliases

NameTypeDescription
first Returns optional front of range
last Returns optional end of range