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'
at(index)
at<
Index
>(index
): <Value
>(iterable
) =>Optional
<Value
>
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.
Type Parameters
• Index extends number
Parameters
• index: NonNegativeInteger
<Index
>
Returns
Function
Type Parameters
• Value
Parameters
• iterable: Iterable
<Value
, any
, any
>
Returns
Optional
<Value
>
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'
Defined in
at(index, iterable)
at<
Index
,Value
>(index
,iterable
):Optional
<Value
>
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.
Type Parameters
• Index extends number
• Value
Parameters
• index: NonNegativeInteger
<Index
>
• iterable: Iterable
<Value
, any
, any
>
Returns
Optional
<Value
>
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'