Skip to main content

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

NameDescription
TSource element type.

Parameters

NameTypeDescription
predicate(arg: T, index: number) => booleanCondition.

Returns

SeqToValue<T, boolean>

Defined in

every.ts:19


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

NameDescription
TSource element type.

Parameters

NameTypeDescription
predicate(arg: T, index: number) => booleanCondition.

Returns

SeqToValue<T, T>

The first element that matches the condition

Defined in

find.ts:17


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

NameDescription
TSource element type.

Parameters

NameTypeDefault valueDescription
predicate(arg: T, index: number) => booleanundefinedCondition.
defaultValueundefined | TundefinedDefault value.

Returns

fn

The first element that matches the condition, or the default value.

▸ (seq): undefined | T

Parameters
NameType
seqSeq<T>
Returns

undefined | T

Defined in

findOrDefault.ts:18


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

NameDescription
TSource element type.
TAccumulateThe type returned by the aggregate function.

Parameters

NameTypeDescription
seedTAccumulateThis is the initial value for aggregation.
func(previous: TAccumulate, current: T, index: number) => TAccumulateAggregate function.

Returns

fn

Aggregate results.

▸ (seq): TAccumulate

Parameters
NameType
seqSeq<T>
Returns

TAccumulate

Defined in

reduce.ts:22


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

NameDescription
TSource element type.

Parameters

NameTypeDescription
predicate(arg: T, index: number) => booleanCondition.

Returns

fn

▸ (seq): boolean

Parameters
NameType
seqSeq<T>
Returns

boolean

Defined in

some.ts:19

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

NameDescription
TSource element type.

Parameters

NameTypeDescription
predicate(arg: T, index: number) => boolean | Promise<boolean>Condition.

Returns

AsyncSeqToValue<T, boolean>

Defined in

async/everyAsync.ts:23


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

NameDescription
TSource element type.

Parameters

NameTypeDescription
predicate(arg: T, index: number) => boolean | Promise<boolean>Condition.

Returns

AsyncSeqToValue<T, T>

The first element that matches the condition

Defined in

async/findAsync.ts:19


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

NameDescription
TSource element type.

Parameters

NameTypeDefault valueDescription
predicate(arg: T, index: number) => boolean | Promise<boolean>undefinedCondition.
defaultValueundefined | TundefinedDefault 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

NameDescription
TSource element type.
TAccumulateThe type returned by the aggregate function.

Parameters

NameTypeDescription
seedTAccumulateThis is the initial value for aggregation.
func(previous: TAccumulate, current: T, index: number) => Promise<TAccumulate>Aggregate function.

Returns

AsyncSeqToValue<T, TAccumulate>

Aggregate results.

Defined in

async/reduceAsync.ts:22


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

NameDescription
TSource element type.

Parameters

NameTypeDescription
predicate(arg: T, index: number) => boolean | Promise<boolean>Condition.

Returns

AsyncSeqToValue<T, boolean>

Defined in

async/someAsync.ts:23