Values
every
▸ every<T
>(predicate
): SeqToValue
<T
, boolean
>
Returns whether or not all elements of a sequence meet the specified conditions.
const result1 = from([2,4,6]).value(every(i => i % 2 == 0));
//result1: true
const result2 = from([2,4,6,7]).value(every(i => i % 2 == 0));
//result2: false
Type parameters
Name | Description |
---|---|
T | Source element type. |
Parameters
Name | Type | Description |
---|---|---|
predicate | (arg : T , index : number ) => boolean | Condition. |
Returns
SeqToValue
<T
, boolean
>
Defined in
find
▸ find<T
>(predicate?
): SeqToValue
<T
, T
>
Returns the first element that satisfies the condition. If no element satisfying the condition is found, an error is thrown.
const result = from([1,2,3,4]).value(find(i => i % 2 == 0));
//result: 2
Type parameters
Name | Description |
---|---|
T | Source element type. |
Parameters
Name | Type | Description |
---|---|---|
predicate | (arg : T , index : number ) => boolean | Condition. |
Returns
SeqToValue
<T
, T
>
The first element that matches the condition
Defined in
findOrDefault
▸ findOrDefault<T
>(predicate?
, defaultValue?
): (seq
: Seq
<T
>) => undefined
| T
Returns the first element that satisfies the condition. If no element is found that satisfies the condition, it returns the specified default value.
const result = from([1,3,5,7]).value(findOrDefault(i => i % 2 == 0, 9999));
//result: 9999
Type parameters
Name | Description |
---|---|
T | Source element type. |
Parameters
Name | Type | Default value | Description |
---|---|---|---|
predicate | (arg : T , index : number ) => boolean | undefined | Condition. |
defaultValue | undefined | T | undefined | Default value. |
Returns
fn
The first element that matches the condition, or the default value.
▸ (seq
): undefined
| T
Parameters
Name | Type |
---|---|
seq | Seq <T > |
Returns
undefined
| T
Defined in
reduce
▸ reduce<T
, TAccumulate
>(seed
, func
): (seq
: Seq
<T
>) => TAccumulate
Returns the result of applying the aggregate function to the elements of the current sequence. The difference with scan() is that it only returns the final result.
const output = from([1, 2, 3, 4, 5]).value(
reduce(100, (acc, i) => acc + i)
);
//result: 115
Type parameters
Name | Description |
---|---|
T | Source element type. |
TAccumulate | The type returned by the aggregate function. |
Parameters
Name | Type | Description |
---|---|---|
seed | TAccumulate | This is the initial value for aggregation. |
func | (acc : TAccumulate , current : T , index : number ) => TAccumulate | Aggregate function. |
Returns
fn
Aggregate results.
▸ (seq
): TAccumulate
Parameters
Name | Type |
---|---|
seq | Seq <T > |
Returns
TAccumulate
Defined in
some
▸ some<T
>(predicate?
): (seq
: Seq
<T
>) => boolean
Returns whether or not any element of the sequence satisfies the specified condition.
const result1 = from([1,3,5,6,7]).value(some(i => i % 2 == 0));
//result1: true
const result2 = from([1,3,5,7]).value(some(i => i % 2 == 0));
//result2: false
Type parameters
Name | Description |
---|---|
T | Source element type. |
Parameters
Name | Type | Description |
---|---|---|
predicate | (arg : T , index : number ) => boolean | Condition. |
Returns
fn
▸ (seq
): boolean
Parameters
Name | Type |
---|---|
seq | Seq <T > |
Returns
boolean
Defined in
Async Values
everyAsync
▸ everyAsync<T
>(predicate
): AsyncSeqToValue
<T
, boolean
>
Returns whether or not all elements of a sequence meet the specified conditions.
const result1 = await fromAsAsync([2,4,6]).valueAsync(
everyAsync(async i => i % 2 == 0)
);
//result1: true
const result2 = await fromAsAsync([2,4,6,7]).valueAsync(
everyAsync(async i => i % 2 == 0)
);
//result2: false
Type parameters
Name | Description |
---|---|
T | Source element type. |
Parameters
Name | Type | Description |
---|---|---|
predicate | (arg : T , index : number ) => boolean | Promise <boolean > | Condition. |
Returns
AsyncSeqToValue
<T
, boolean
>
Defined in
findAsync
▸ findAsync<T
>(predicate?
): AsyncSeqToValue
<T
, T
>
Returns the first element that satisfies the condition. If no element satisfying the condition is found, an error is thrown.
const result = await fromAsAsync([1,2,3,4]).valueAsync(
findAsync(async i => i % 2 == 0)
);
//result: 2
Type parameters
Name | Description |
---|---|
T | Source element type. |
Parameters
Name | Type | Description |
---|---|---|
predicate | (arg : T , index : number ) => boolean | Promise <boolean > | Condition. |
Returns
AsyncSeqToValue
<T
, T
>
The first element that matches the condition
Defined in
findOrDefaultAsync
▸ findOrDefaultAsync<T
>(predicate?
, defaultValue?
): AsyncSeqToValue
<T
, undefined
| T
>
Returns the first element that satisfies the condition. If no element is found that satisfies the condition, it returns the specified default value.
const result = await fromAsAsync([1,3,5,7]).valueAsync(
findOrDefaultAsync(async i => i % 2 == 0, 9999)
);
//result: 9999
Type parameters
Name | Description |
---|---|
T | Source element type. |
Parameters
Name | Type | Default value | Description |
---|---|---|---|
predicate | (arg : T , index : number ) => boolean | Promise <boolean > | undefined | Condition. |
defaultValue | undefined | T | undefined | Default value. |
Returns
AsyncSeqToValue
<T
, undefined
| T
>
The first element that matches the condition, or the default value.
Defined in
async/findOrDefaultAsync.ts:20
reduceAsync
▸ reduceAsync<T
, TAccumulate
>(seed
, func
): AsyncSeqToValue
<T
, TAccumulate
>
Returns the result of applying the aggregate function to the elements of the current sequence. The difference with scan() is that it only returns the final result.
const output = await fromAsAsync([1, 2, 3, 4, 5]).valueAsync(
reduceAsync(100, async (acc, i) => acc + i)
);
//result: 115
Type parameters
Name | Description |
---|---|
T | Source element type. |
TAccumulate | The type returned by the aggregate function. |
Parameters
Name | Type | Description |
---|---|---|
seed | TAccumulate | This is the initial value for aggregation. |
func | (acc : TAccumulate , current : T , index : number ) => Promise <TAccumulate > | Aggregate function. |
Returns
AsyncSeqToValue
<T
, TAccumulate
>
Aggregate results.
Defined in
someAsync
▸ someAsync<T
>(predicate?
): AsyncSeqToValue
<T
, boolean
>
Returns whether or not any element of the sequence satisfies the specified condition.
const result1 = await fromAsync([1,3,5,6,7]).valueAsync(
someAsync(async i => i % 2 == 0)
);
//result1: true
const result2 = await fromAsync([1,3,5,7]).valueAsync(
someAsync(async i => i % 2 == 0)
);
//result2: false
Type parameters
Name | Description |
---|---|
T | Source element type. |
Parameters
Name | Type | Description |
---|---|---|
predicate | (arg : T , index : number ) => boolean | Promise <boolean > | Condition. |
Returns
AsyncSeqToValue
<T
, boolean
>