Iterables Reference
🔁 Iterable and AsyncIterable utils.
Usage
By default, all utils are meant to be used with Iterable
values, to use
AsyncIterable
values the functions have to be imported from
@lou.codes/iterables/asynchronous
.
📦 Node
Install @lou.codes/iterables
as a dependency:
Import it and use it:
🦕 Deno
Import @lou.codes/iterables
using the npm:
prefix, and use it directly:
🌎 Browser
Import @lou.codes/iterables
using esm.sh, and use it directly:
Useful links
- 📝 Documentation: TypeDoc generated documentation.
- ⏳ Changelog: List of changes between versions.
- ✅ Tests Coverage: Coveralls page with tests coverage.
Asynchronous
Asynchronous Common
createIterableIterator()
Takes a generator function and returns an iterable iterator or asynchronous iterable iterator object.
Type parameters
Type parameter |
---|
GeneratorFunction extends () => IsomorphicIterator |
Parameters
Parameter | Type | Description |
---|---|---|
generatorFunction | GeneratorFunction | Generator to be used every time [Symbol.iterator] is called. |
Returns
GeneratorFunction
extends () => IsomorphicIterator
<Item
> ?
Readonly
<GeneratorFunction
<GeneratorFunction
> extends
(…_arguments
: _Arguments
) => AsyncIterator
<Item
, any
, undefined
>
? AsyncIterableIterator
<Item
> : IterableIterator
<Item
>> : never
Iterable iterator object.
Example
forEach()
For each function for iterables and asynchronous iterables.
Type parameters
Type parameter |
---|
Item |
Parameters
Parameter | Type | Description |
---|---|---|
callback | Unary <Item , Awaitable <void >> | Function to be called for every item of the iterable. |
Returns
Function
Curried function that expects an iterable to loop over and has callback
set in
context.
Parameters
Parameter | Type |
---|---|
iterable | IsomorphicIterable <Item > |
Returns
Promise
<void
>
Example
Asynchronous Generators
append()
Appends one iterable or asynchronous iterable to another.
Type parameters
Type parameter |
---|
TailItem |
Parameters
Parameter | Type | Description |
---|---|---|
tailIterable | IsomorphicIterable <TailItem > | Iterable or asynchronous to be appended. |
Returns
Function
Curried generator function with tailIterable
set in context.
Type parameters
Type parameter |
---|
InitialItem |
Parameters
Parameter | Type |
---|---|
initialIterable | IsomorphicIterable <InitialItem > |
Returns
Readonly
<AsyncIterableIterator
<Awaited
<InitialItem
> |
Awaited
<TailItem
>>>
Example
drop()
Drop the specified amount of items from the given iterable or asynchronous iterable.
Parameters
Parameter | Type | Description |
---|---|---|
amount | Numeric | Amount of items to drop. |
Returns
Function
Curried function with amount
in context.
Type parameters
Type parameter |
---|
Item |
Parameters
Parameter | Type |
---|---|
iterable | IsomorphicIterable <Item > |
Returns
Readonly
<AsyncIterableIterator
<Awaited
<Item
>>>
Example
filter()
Filters items in an iterable or asynchronous iterable against a predicate and
returns items that evaluated to true
.
Type parameters
Type parameter | Value |
---|---|
Item | - |
Filtered | never |
Parameters
Parameter | Type | Description |
---|---|---|
predicate | Single <Filtered > extends Single <never > ? Unary <Item , boolean > : Predicate <Item , Filtered > | Predicate function to evaluate each item. |
Returns
Function
Curried function with predicate
set in context.
Parameters
Parameter | Type |
---|---|
iterable | IsomorphicIterable <Item > |
Returns
Readonly
<AsyncIterableIterator
<Awaited
<Filtered
>>>
Example
flat()
Flattens one level of the given iterable or asynchronous iterable.
Type parameters
Type parameter |
---|
Iterable extends IsomorphicIterable |
Parameters
Parameter | Type | Description |
---|---|---|
iterable | Iterable | Iterable to flatten. |
Returns
Iterable
extends IsomorphicIterable
<Item
> ? Readonly
<Item
extends IsomorphicIterable
<SubItem
> ?
AsyncIterableIterator
<SubItem
> : AsyncIterableIterator
<Item
>> :
never
Iterable with flatten items.
Example
initial()
Get all elements except the last one of an iterable or asynchronous iterable.
Type parameters
Type parameter |
---|
Iterable extends IsomorphicIterable |
Parameters
Parameter | Type | Description |
---|---|---|
iterable | Iterable | Iterable to get the items from. |
Returns
IsomorphicIterableIterator
<IsomorphicIterableItem
<Iterable
>>
Iterable with all items except the last one.
Example
intersperse()
Add the given separator
between each element of the given iterable or
asynchronous iterable.
Type parameters
Type parameter |
---|
Separator |
Parameters
Parameter | Type | Description |
---|---|---|
separator | Separator | Separator to add between each element. |
Returns
Function
Curried function with separator
in context.
Type parameters
Type parameter |
---|
Item |
Parameters
Parameter | Type |
---|---|
iterable | IsomorphicIterable <Item > |
Returns
IsomorphicIterableIterator
<Item
| Awaited
<Separator
> |
Awaited
<Item
>>
Example
map()
Map for iterables and asynchronous iterables.
Type parameters
Type parameter |
---|
Item |
MappedItem |
Parameters
Parameter | Type | Description |
---|---|---|
mapper | Unary <Item , MappedItem > | Mapper function. |
Returns
Function
Generator function with mapper
function set in context.
Parameters
Parameter | Type |
---|---|
iterable | IsomorphicIterable <Item > |
Returns
Readonly
<AsyncIterableIterator
<Awaited
<MappedItem
>>>
Example
objectToEntries()
Yields all entries of an object (including symbols).
Type parameters
Type parameter |
---|
Key extends PropertyKey |
Value |
Parameters
Parameter | Type | Description |
---|---|---|
input | Readonly <Record <Key , Value >> | Object to get entries from. |
Returns
Readonly
<AsyncIterableIterator
<Entry
<Key
, Value
>>>
Iterable with entries of the given object (including symbols).
Example
prepend()
Prepends one iterable or asynchronous iterable to another.
Type parameters
Type parameter |
---|
InitialItem |
Parameters
Parameter | Type | Description |
---|---|---|
initialIterable | IsomorphicIterable <InitialItem > | Iterable or asynchronous iterable to be appended. |
Returns
Function
Curried generator function with initialIterable
set in context.
Type parameters
Type parameter |
---|
TailItem |
Parameters
Parameter | Type |
---|---|
tailIterable | IsomorphicIterable <TailItem > |
Returns
Readonly
<AsyncIterableIterator
<Awaited
<InitialItem
> |
Awaited
<TailItem
>>>
Example
random()
Deterministic pseudo-random number generator.
⚠️ IMPORTANT: This only works in secure contexts (HTTPS/Node).
Parameters
Parameter | Type | Description |
---|---|---|
seed | string | Numeric | Seed to be used to generate random numbers. |
Returns
Function
Curried generator function with seed
set in context.
Parameters
Parameter | Type |
---|---|
from | number |
Returns
Function
Parameters
Parameter | Type |
---|---|
to | number |
Returns
Readonly
<AsyncIterableIterator
<number
>>
Example
See
range()
Range iterable generator (from from
to to
).
Type parameters
Type parameter |
---|
Step extends Numeric |
Parameters
Parameter | Type | Description |
---|---|---|
step | Step | Step size. |
Returns
Function
Curried function with step
set in context.
Parameters
Parameter | Type |
---|---|
from | Step extends bigint ? bigint : number |
Returns
Function
Parameters
Parameter | Type |
---|---|
to | Step extends bigint ? bigint : number |
Returns
Readonly
<AsyncIterableIterator
<Step
extends bigint
? bigint
:
number
>>
Example
repeat()
Repeat given item the specified amount of times (can be BigInt
or Infinity
times) as an iterable.
Parameters
Parameter | Type |
---|---|
times | Numeric |
Returns
Function
Curried function with item
in context.
Type parameters
Type parameter |
---|
Item |
Parameters
Parameter | Type |
---|---|
item | Item |
Returns
Readonly
<AsyncIterableIterator
<Awaited
<Item
>>>
Example
take()
Take the given amount of items from the iterable or asynchronous iterable.
Parameters
Parameter | Type | Description |
---|---|---|
amount | Numeric | Amount of items to take. |
Returns
Function
Curried function with amount
in context.
Type parameters
Type parameter |
---|
Item |
Parameters
Parameter | Type |
---|---|
iterable | IsomorphicIterable <Item > |
Returns
Readonly
<AsyncIterableIterator
<Awaited
<Item
>>>
Example
toIterable()
Takes a value, iterable or asynchronous iterable and yields it.
Type parameters
Type parameter |
---|
ValueOrAsyncIterable |
Parameters
Parameter | Type | Description |
---|---|---|
valueOrIterable | ValueOrAsyncIterable | Vale or iterable to yield. |
Returns
Readonly
<AsyncIterableIterator
<ValueOrAsyncIterable
extends
IsomorphicIterable
?
IsomorphicIterableItem
<ValueOrAsyncIterable
<ValueOrAsyncIterable
>> :
ValueOrAsyncIterable
>>
Yielded item or iterable.
Example
See
unique()
Returns a single instance of each item in the iterable or asynchronous iterable.
Type parameters
Type parameter |
---|
Item |
Parameters
Parameter | Type | Description |
---|---|---|
iterable | IsomorphicIterable <Item > | Iterable to be filtered. |
Returns
Readonly
<AsyncIterableIterator
<Awaited
<Item
>>>
Generators with a single instance of each item of the iterable.
Example
zip()
Takes two iterables or asynchronous iterable and returns a new iterable or asynchronous iterable with the length of the shortest iterable with tuples containing the items from both.
Type parameters
Type parameter |
---|
ItemFirst |
Parameters
Parameter | Type | Description |
---|---|---|
iterableFirst | IsomorphicIterable <ItemFirst > | One of the iterables to be zipped. |
Returns
Function
Curried function with iterableFirst
in context.
Type parameters
Type parameter |
---|
ItemSecond |
Parameters
Parameter | Type |
---|---|
iterableSecond | IsomorphicIterable <ItemSecond > |
Returns
Readonly
<AsyncIterableIterator
<readonly [ItemFirst
| Awaited
<ItemFirst
>, ItemSecond
]>>
Example
zipIndex()
Yields a tuple for each item in the iterable with the index of said item.
Type parameters
Type parameter |
---|
ItemSecond |
Parameters
Parameter | Type |
---|---|
iterableSecond | IsomorphicIterable <ItemSecond > |
Returns
Readonly
<AsyncIterableIterator
<readonly [number
, ItemSecond
]>>
Example
Yields
Tuples with the index of each item.
Asynchronous Reducers
count()
Counts the number of items that satisfy a predicate in the given iterable or asynchronous iterable.
Type parameters
Type parameter |
---|
Item |
Parameters
Parameter | Type | Description |
---|---|---|
predicate | Filter <Item > | Predicate function for items to be counted. |
Returns
Function
Curried function with predicate
in context.
Parameters
Parameter | Type |
---|---|
iterable | IsomorphicIterable <Item > |
Returns
Promise
<number
>
Example
entriesToObject()
Takes an entries iterable or asynchronous iterable and returns an object.
Type parameters
Type parameter |
---|
Item extends Entry |
Parameters
Parameter | Type |
---|---|
iterable | IsomorphicIterable <Item > |
Returns
Promise
<Readonly
<Record
<EntryKey
<Item
>,
EntryValue
<Item
>>>>
Object constructed from entries.
Example
every()
Evaluates items in an iterable or asynchronous iterable against a predicate and
returns true
if all items evaluates to true
.
Type parameters
Type parameter | Value |
---|---|
Item | - |
Predicated | never |
Parameters
Parameter | Type | Description |
---|---|---|
predicate | Single <Predicated > extends Single <never > ? Unary <Item , boolean > : Predicate <Item , Predicated > | Predicate function to evaluate each item. |
Returns
Function
Curried function with predicate
set in context.
Parameters
Parameter | Type |
---|---|
iterable | IsomorphicIterable <Item > |
Returns
Promise
<boolean
>
Example
find()
Returns the value of the first item in the iterable or asynchronous iterable
where predicate is true
, undefined
otherwise.
Type parameters
Type parameter |
---|
Item |
Parameters
Parameter | Type | Description |
---|---|---|
predicate | Unary <Item , boolean > | Predicate function to search for item. |
Returns
Function
Curried function with predicate
set in context.
Parameters
Parameter | Type |
---|---|
iterable | IsomorphicIterable <Item > |
Returns
Promise
<Maybe
<Item
>>
Example
groupBy()
Groups values of an iterable or asynchronous iterable in an object based on the
output of the grouper
function.
Type parameters
Type parameter |
---|
Item |
Key extends PropertyKey |
Parameters
Parameter | Type | Description |
---|---|---|
grouper | Unary <Item , Key > | Grouper function. |
Returns
Function
Object with grouped values.
Type parameters
Type parameter |
---|
Iterable extends IsomorphicIterable <Item > |
Parameters
Parameter | Type |
---|---|
iterable | Iterable |
Returns
Iterable
extends AsyncIterable
<unknown
> ?
Promise
<Readonly
<Record
<Key
, ReadOnlyArray
<Item
>>>> :
Readonly
<Record
<Key
, ReadOnlyArray
<Item
>>>
Example
head()
Get first element of an iterable or asynchronous iterable (undefined
if it is
empty).
Type parameters
Type parameter |
---|
Iterable extends IsomorphicIterable |
Parameters
Parameter | Type | Description |
---|---|---|
iterable | Iterable | Iterable to get the first element from. |
Returns
Iterable
extends ReadOnlyArray
? Head
<Iterable
<Iterable
>> :
Maybe
<IsomorphicIterableItem
<Iterable
>>
First element of the iterable (undefined
if empty).
Example
includes()
Tries to find the given searchItem
in iterable or asynchronous iterable.
Type parameters
Type parameter |
---|
SearchItem |
Parameters
Parameter | Type | Description |
---|---|---|
searchItem | SearchItem | Item to search. |
Returns
Function
Curried function with searchItem
set in context.
Parameters
Parameter | Type |
---|---|
iterable | IsomorphicIterable <unknown > |
Returns
Promise
<boolean
>
Example
iterableToArray()
Turns given iterable or asynchronous iterable into an array.
Type parameters
Type parameter |
---|
Iterable extends IsomorphicIterable |
Parameters
Parameter | Type | Description |
---|---|---|
iterable | Iterable | Iterable to be turned into an array. |
Returns
Promise
<ReadOnlyArray
<IsomorphicIterableItem
<Iterable
>>>
Array made of iterable items.
Example
join()
Takes a separator
string and a iterable or asynchronous iterable and returns a
string with the concatenation of all the elements separated by the separator
.
Type parameters
Type parameter |
---|
Separator extends string |
Parameters
Parameter | Type | Description |
---|---|---|
separator | Separator | String to use as separator. |
Returns
Function
Curried function with separator
in context.
Type parameters
Type parameter |
---|
Iterable extends IsomorphicIterable |
Parameters
Parameter | Type |
---|---|
iterable | Iterable |
Returns
Iterable
extends AsyncIterable
<unknown
> ?
Promise
<`${string}${Separator}${string}`> : `${string}${Separator}${string}`
Example
length()
Get the length of an iterable or asynchronous iterable.
Type parameters
Type parameter |
---|
Iterable extends IsomorphicIterable <unknown > |
Parameters
Parameter | Type | Description |
---|---|---|
iterable | Iterable | Iterable or asynchronous iterable to get the length from. |
Returns
Iterable
extends AsyncIterable
<unknown
> ? Promise
<number
> :
number
Promise with the length of the iterable.
Example
reduce()
Reducer function for iterables and asynchronous iterables.
Type parameters
Type parameter |
---|
Item |
Accumulator |
Parameters
Parameter | Type | Description |
---|---|---|
reducer | Unary <Item , Unary <Accumulator , Awaitable <Accumulator >>> | Reducer function. |
Returns
Function
Curried function with reducer
in context.
Parameters
Parameter | Type |
---|---|
initialValue | Accumulator |
Returns
Function
Type parameters
Type parameter |
---|
Iterable extends IsomorphicIterable <Item > |
Parameters
Parameter | Type |
---|---|
iterable | Iterable |
Returns
Iterable
extends AsyncIterable
<unknown
> ? Promise
<Accumulator
> :
Accumulator
Example
some()
Evaluates items in an iterable or asynchronous iterable against a predicate and
returns true
if any item evaluates to true
.
Type parameters
Type parameter | Value |
---|---|
Item | - |
Predicated | never |
Parameters
Parameter | Type | Description |
---|---|---|
predicate | Single <Predicated > extends Single <never > ? Unary <Item , boolean > : Predicate <Item , Predicated > | Predicate function to evaluate each item. |
Returns
Function
Curried function with predicate
set in context.
Parameters
Parameter | Type |
---|---|
iterable | IsomorphicIterable <Item > |
Returns
Promise
<boolean
>
Example
Internal
setAsyncIterator()
Set Symbol.asyncIterator
to the given value to the given object.
Type parameters
Type parameter |
---|
Value |
Parameters
Parameter | Type |
---|---|
value | Value |
Returns
Function
Curried function with key
in context.
Type parameters
Type parameter |
---|
Source extends object |
Parameters
Parameter | Type |
---|---|
object | Source |
Returns
Omit
<Source
, typeof asyncIterator
> & Readonly
<Record
<typeof
asyncIterator
, Value
>>
Example
Synchronous
Common
createIterableIterator()
Takes a generator function and returns an iterable iterator object.
Type parameters
Type parameter |
---|
Item |
Parameters
Parameter | Type | Description |
---|---|---|
generatorFunction | () => Readonly <Iterator <Item , void , void >> | Generator to be used every time [Symbol.iterator] is called. |
Returns
Readonly
<IterableIterator
<Item
>>
Iterable iterator object.
Example
forEach()
For each function for iterables.
Type parameters
Type parameter |
---|
Item |
Parameters
Parameter | Type | Description |
---|---|---|
callback | Unary <Item , void > | Function to be called for every item of the iterable. |
Returns
Function
Curried function that expects an iterable to loop over and has callback
set in
context.
Parameters
Parameter | Type |
---|---|
iterable | Readonly <Iterable <Item >> |
Returns
void
Example
Generators
append()
Appends one iterable to another.
Type parameters
Type parameter |
---|
TailItem |
Parameters
Parameter | Type | Description |
---|---|---|
tailIterable | Readonly <Iterable <TailItem >> | Iterable to be appended. |
Returns
Function
Curried generator function with tailIterable
set in context.
Type parameters
Type parameter |
---|
InitialItem |
Parameters
Parameter | Type |
---|---|
initialIterable | Readonly <Iterable <InitialItem >> |
Returns
Readonly
<IterableIterator
<TailItem
| InitialItem
>>
Example
drop()
Drop the specified amount of items from the given iterable.
Parameters
Parameter | Type | Description |
---|---|---|
amount | Numeric | Amount of items to drop. |
Returns
Function
Curried function with amount
in context.
Type parameters
Type parameter |
---|
Item |
Parameters
Parameter | Type |
---|---|
iterable | Readonly <Iterable <Item >> |
Returns
Readonly
<IterableIterator
<Item
>>
Example
filter()
Filters items in an iterable against a predicate and returns items that
evaluated to true
.
Type parameters
Type parameter | Value |
---|---|
Item | - |
Filtered | never |
Parameters
Parameter | Type | Description |
---|---|---|
predicate | Single <Filtered > extends Single <never > ? Unary <Item , boolean > : Predicate <Item , Filtered > | Predicate function to evaluate each item. |
Returns
Function
Curried function with predicate
set in context.
Parameters
Parameter | Type |
---|---|
iterable | Readonly <Iterable <Item >> |
Returns
Readonly
<IterableIterator
<Filtered
>>
Example
flat()
Flattens one level of the given iterable.
Type parameters
Type parameter |
---|
Iterable extends Readonly <Iterable <unknown >> |
Parameters
Parameter | Type | Description |
---|---|---|
iterable | Iterable | Iterable to flatten. |
Returns
Iterable
extends Readonly
<Iterable
<Item
>> ? Item
extends
Readonly
<Iterable
<SubItem
>> ?
Readonly
<IterableIterator
<SubItem
>> :
Readonly
<IterableIterator
<Item
>> : never
Iterable with flatten items.
Example
initial()
Get all elements except the last one of an iterable.
Type parameters
Type parameter |
---|
Iterable extends Readonly <Iterable <unknown >> |
Parameters
Parameter | Type | Description |
---|---|---|
iterable | Iterable | Iterable to get the items from. |
Returns
Readonly
<IterableIterator
<Iterable
extends ReadOnlyArray
?
Initial
<Iterable
<Iterable
>>[number
] :
IsomorphicIterableItem
<Iterable
>>>
Iterable with all items except the last one.
Example
intersperse()
Add the given separator
between each element of the given iterable.
Type parameters
Type parameter |
---|
Separator |
Parameters
Parameter | Type | Description |
---|---|---|
separator | Separator | Separator to add between each element. |
Returns
Function
Curried function with separator
in context.
Type parameters
Type parameter |
---|
Item |
Parameters
Parameter | Type |
---|---|
iterable | Readonly <Iterable <Item >> |
Returns
Readonly
<IterableIterator
<Separator
| Item
>>
Example
map()
Map for iterables.
Type parameters
Type parameter |
---|
Item |
MappedItem |
Parameters
Parameter | Type | Description |
---|---|---|
mapper | Unary <Item , MappedItem > | Mapper function. |
Returns
Function
Generator function with mapper
function set in context.
Parameters
Parameter | Type |
---|---|
iterable | Readonly <Iterable <Item >> |
Returns
Readonly
<IterableIterator
<MappedItem
>>
Example
objectToEntries()
Yields all entries of an object (including symbols).
Type parameters
Type parameter |
---|
Key extends PropertyKey |
Value |
Parameters
Parameter | Type | Description |
---|---|---|
input | Readonly <Record <Key , Value >> | Object to get entries from. |
Returns
Readonly
<IterableIterator
<Entry
<Key
, Value
>>>
Iterable with entries of the given object (including symbols).
Example
prepend()
Prepends one iterable to another.
Type parameters
Type parameter |
---|
InitialItem |
Parameters
Parameter | Type | Description |
---|---|---|
initialIterable | Readonly <Iterable <InitialItem >> | Iterable to be appended. |
Returns
Function
Curried generator function with initialIterable
set in context.
Type parameters
Type parameter |
---|
TailItem |
Parameters
Parameter | Type |
---|---|
tailIterable | Readonly <Iterable <TailItem >> |
Returns
Readonly
<IterableIterator
<InitialItem
| TailItem
>>
Example
range()
Range iterable generator (from from
to to
).
Type parameters
Type parameter |
---|
Step extends Numeric |
Parameters
Parameter | Type | Description |
---|---|---|
step | Step | Step size. |
Returns
Function
Curried function with step
set in context.
Parameters
Parameter | Type |
---|---|
from | Step extends bigint ? bigint : number |
Returns
Function
Parameters
Parameter | Type |
---|---|
to | Step extends bigint ? bigint : number |
Returns
Readonly
<IterableIterator
<Step
extends bigint
? bigint
:
number
>>
Example
repeat()
Repeat given item the specified amount of times (can be BigInt
or Infinity
times) as an iterable.
Parameters
Parameter | Type |
---|---|
times | Numeric |
Returns
Function
Curried function with item
in context.
Type parameters
Type parameter |
---|
Item |
Parameters
Parameter | Type |
---|---|
item | Item |
Returns
Readonly
<IterableIterator
<Item
>>
Example
take()
Take the given amount of items from the iterable.
Parameters
Parameter | Type | Description |
---|---|---|
amount | Numeric | Amount of items to take. |
Returns
Function
Curried function with amount
in context.
Type parameters
Type parameter |
---|
Item |
Parameters
Parameter | Type |
---|---|
iterable | Readonly <Iterable <Item >> |
Returns
Readonly
<IterableIterator
<Item
>>
Example
toIterable()
Takes a value, iterable and yields it.
Type parameters
Type parameter | Description |
---|---|
ValueOrIterable | Generic of value or iterable to yield. |
Parameters
Parameter | Type | Description |
---|---|---|
valueOrIterable | ValueOrIterable | Vale or iterable to yield. |
Returns
Readonly
<IterableIterator
<ValueOrIterable
extends IsomorphicIterable
? IsomorphicIterableItem
<ValueOrIterable
<ValueOrIterable
>> :
ValueOrIterable
>>
Yielded item or iterable.
Example
See
unique()
Returns a single instance of each item in the iterable.
Type parameters
Type parameter |
---|
Item |
Parameters
Parameter | Type | Description |
---|---|---|
iterable | Readonly <Iterable <Item >> | Iterable to be filtered. |
Returns
Readonly
<IterableIterator
<Item
>>
Generators with a single instance of each item of the iterable.
Example
zip()
Takes two iterables and returns a new iterable with the length of the shortest iterable with tuples containing the items from both.
Type parameters
Type parameter |
---|
ItemFirst |
Parameters
Parameter | Type | Description |
---|---|---|
iterableFirst | Readonly <Iterable <ItemFirst >> | One of the iterables to be zipped. |
Returns
Function
Curried function with iterableFirst
in context.
Type parameters
Type parameter |
---|
ItemSecond |
Parameters
Parameter | Type |
---|---|
iterableSecond | Readonly <Iterable <ItemSecond >> |
Returns
Readonly
<IterableIterator
<readonly [ItemFirst
, ItemSecond
]>>
Example
zipIndex()
Yields a tuple for each item in the iterable with the index of said item.
Type parameters
Type parameter |
---|
ItemSecond |
Parameters
Parameter | Type |
---|---|
iterableSecond | Readonly <Iterable <ItemSecond >> |
Returns
Readonly
<IterableIterator
<readonly [number
, ItemSecond
]>>
Example
Yields
Tuples with the index of each item.
Internal
setIterator()
Set Symbol.iterator
to the given value to the given object.
Type parameters
Type parameter |
---|
Value |
Parameters
Parameter | Type |
---|---|
value | Value |
Returns
Function
Curried function with key
in context.
Type parameters
Type parameter |
---|
Source extends object |
Parameters
Parameter | Type |
---|---|
object | Source |
Returns
Omit
<Source
, typeof iterator
> & Readonly
<Record
<typeof
iterator
, Value
>>
Example
Reducers
count()
Counts the number of items that satisfy a predicate in the given iterable.
Type parameters
Type parameter |
---|
Item |
Parameters
Parameter | Type | Description |
---|---|---|
predicate | Filter <Item > | Predicate function for items to be counted. |
Returns
Function
Curried function with predicate
in context.
Parameters
Parameter | Type |
---|---|
iterable | Readonly <Iterable <Item >> |
Returns
number
Example
entriesToObject()
Takes an entries iterable and returns an object.
Type parameters
Type parameter |
---|
Item extends Entry |
Parameters
Parameter | Type |
---|---|
iterable | Readonly <Iterable <Item >> |
Returns
Readonly
<Record
<EntryKey
<Item
>, EntryValue
<Item
>>>
Object constructed from entries.
Example
every()
Evaluates items in an iterable against a predicate and returns true
if all
items evaluates to true
.
Type parameters
Type parameter | Value |
---|---|
Item | - |
Predicated | never |
Parameters
Parameter | Type | Description |
---|---|---|
predicate | Single <Predicated > extends Single <never > ? Unary <Item , boolean > : Predicate <Item , Predicated > | Predicate function to evaluate each item. |
Returns
Function
Curried function with predicate
set in context.
Parameters
Parameter | Type |
---|---|
iterable | Readonly <Iterable <Item >> |
Returns
boolean
Example
find()
Returns the value of the first item in the iterable where predicate is true
,
undefined
otherwise.
Type parameters
Type parameter |
---|
Item |
Parameters
Parameter | Type | Description |
---|---|---|
predicate | Unary <Item , boolean > | Predicate function to search for item. |
Returns
Function
Curried function with predicate
set in context.
Parameters
Parameter | Type |
---|---|
iterable | Readonly <Iterable <Item >> |
Returns
Maybe
<Item
>
Example
groupBy()
Groups values of an iterable in an object based on the output of the grouper
function.
Type parameters
Type parameter |
---|
Item |
Key extends PropertyKey |
Parameters
Parameter | Type | Description |
---|---|---|
grouper | Unary <Item , Key > | Grouper function. |
Returns
Function
Object with grouped values.
Parameters
Parameter | Type |
---|---|
iterable | Readonly <Iterable <Item >> |
Returns
Readonly
<Record
<Key
, ReadOnlyArray
<Item
>>>
Example
head()
Get first element of an iterable (undefined
if it is empty).
Type parameters
Type parameter |
---|
Iterable extends Readonly <Iterable <unknown >> |
Parameters
Parameter | Type | Description |
---|---|---|
iterable | Iterable | Iterable to get the first element from. |
Returns
Iterable
extends ReadOnlyArray
? Head
<Iterable
<Iterable
>> :
Maybe
<IsomorphicIterableItem
<Iterable
>>
First element of the iterable (undefined
if empty).
Example
includes()
Tries to find the given searchItem
in iterable.
Type parameters
Type parameter |
---|
SearchItem |
Parameters
Parameter | Type | Description |
---|---|---|
searchItem | SearchItem | Item to search. |
Returns
Function
Curried function with searchItem
set in context.
Parameters
Parameter | Type |
---|---|
iterable | Readonly <Iterable <unknown >> |
Returns
boolean
Example
iterableToArray()
Turns given iterable into an array.
Type parameters
Type parameter |
---|
Iterable extends Readonly <Iterable <unknown >> |
Parameters
Parameter | Type | Description |
---|---|---|
iterable | Iterable | Iterable to be turned into an array. |
Returns
ReadOnlyArray
<IsomorphicIterableItem
<Iterable
>>
Array made of iterable items.
Example
join()
Takes a separator
string and a iterable and returns a string with the
concatenation of all the elements separated by the separator
.
Type parameters
Type parameter |
---|
Separator extends string |
Parameters
Parameter | Type | Description |
---|---|---|
separator | Separator | String to use as separator. |
Returns
Function
Curried function with separator
in context.
Type parameters
Type parameter |
---|
Item extends Strigifiable |
Parameters
Parameter | Type |
---|---|
iterable | Readonly <Iterable <Item >> |
Returns
`${string}${Separator}${string}`
Example
length()
Get the length of an iterable.
Parameters
Parameter | Type | Description |
---|---|---|
iterable | Readonly <Iterable <unknown >> | Iterable to get the length from. |
Returns
number
Promise with the length of the iterable.
Example
reduce()
Reducer function for iterables.
Type parameters
Type parameter |
---|
Item |
Accumulator |
Parameters
Parameter | Type | Description |
---|---|---|
reducer | Reducer <Item , Accumulator > | Reducer function. |
Returns
Function
Curried function with reducer
in context.
Parameters
Parameter | Type |
---|---|
initialValue | Accumulator |
Returns
Function
Parameters
Parameter | Type |
---|---|
iterable | Readonly <Iterable <Item >> |
Returns
Accumulator
Example
some()
Evaluates items in an iterable against a predicate and returns true
if any
item evaluates to true
.
Type parameters
Type parameter | Value |
---|---|
Item | - |
Predicated | never |
Parameters
Parameter | Type | Description |
---|---|---|
predicate | Single <Predicated > extends Single <never > ? Unary <Item , boolean > : Predicate <Item , Predicated > | Predicate function to evaluate each item. |
Returns
Function
Curried function with predicate
set in context.
Parameters
Parameter | Type |
---|---|
iterable | Readonly <Iterable <Item >> |
Returns
boolean