Skip to main content

Function: at()

Returns an iterable containing the value at the given index of iterable or an empty iterable if index is out of bounds.

WARNING: This function linearly iterates up to index because iterables do not support random access.

Throws

if index is not a non-negative integer.

Example

const iterable = [`sloth`, `more sloth`, `even more sloth`]

console.log(
pipe(
iterable,
at(1),
get,
),
)
//=> 'more sloth'

Since

v3.5.0

Call Signature

at<Index>(index): <Value>(iterable) => Optional<Value>

Type Parameters

Index extends number

Parameters

index

NonNegativeInteger<Index>

Returns

Function

Type Parameters

Value

Parameters

iterable

Iterable<Value, any, any>

Returns

Optional<Value>

Defined in

splices.d.ts:772

Call Signature

at<Index, Value>(index, iterable): Optional<Value>

Type Parameters

Index extends number

Value

Parameters

index

NonNegativeInteger<Index>

iterable

Iterable<Value, any, any>

Returns

Optional<Value>

Defined in

splices.d.ts:775