Home Manual Reference Source

Function

Static Public Summary
public

all(iterable: Iterable): Boolean

Returns true if all of the elements of the input iterable are truthy.

public

any(iterable: Iterable): Boolean

Returns true if any of the elements of the input iterable is truthy.

public

max(compare: Function, iterable: Iterable, dflt: Object): Object

Returns the largest element of the input iterable according to some comparison function.

public

min(compare: Function, iterable: Iterable, dflt: Object): Object

Returns the smallest element of the input iterable according to some comparison function.

public

reduce(accumulator: Function, iterable: Iterable, initializer: Object): Object

Applies the accumulator function iteratively on the last return value of the accumulator and the next value in the input iterable.

public

some(iterable: Iterable, n: Number): Boolean

Returns true if at least some of the elements of the input iterable are truthy.

public

sum(iterable: Iterable, initializer: Object): Object

Sums the elements of the input iterable.

Static Private Summary
private

_reduce(accumulator: Function, iterable: Iterable, initializer: Object): Object

Applies the accumulator function iteratively on the last return value of the accumulator and the next value in the input iterable.

private

_sum(iterable: Iterable, initializer: Object): Object

Sums the elements of the input iterable.

Static Public

public all(iterable: Iterable): Boolean source

Returns true if all of the elements of the input iterable are truthy.

Params:

NameTypeAttributeDescription
iterable Iterable

The input iterable.

Return:

Boolean

Returns true if all element of iterable are truthy, false otherwise.

Example:

all( repeat( true ) ) ; // loops forever
all( repeat( false ) ) ; // returns false
all( chain( [ nrepeat( true , 10 ) , repeat( false ) ) ) ; // returns false

public any(iterable: Iterable): Boolean source

Returns true if any of the elements of the input iterable is truthy.

Params:

NameTypeAttributeDescription
iterable Iterable

The input iterable.

Return:

Boolean

Returns true if any element of iterable is truthy, false otherwise.

Example:

any( repeat( true ) ) ; // returns true
any( repeat( false ) ) ; // loops forever
any( nrepeat( false , 10 ) ) ; // returns false

public max(compare: Function, iterable: Iterable, dflt: Object): Object source

Returns the largest element of the input iterable according to some comparison function.

Params:

NameTypeAttributeDescription
compare Function

The comparison function to use. This function must be 2-ary. It must return -1, 0, or 1 depending whether the first parameter is, respectively, less than, equal to, or greater than the second parameter.

iterable Iterable

The input iterable.

dflt Object
  • optional
  • default: undefined

The default value to return in the case that the input iterable is empty.

Return:

Object

The largest element of iterable according to compare.

Example:

max( ( a , b ) => a - b , range( 10 ) ) ; // returns 9
max( ( a , b ) => a - b , range( 0 ) ) ; // returns undefined

public min(compare: Function, iterable: Iterable, dflt: Object): Object source

Returns the smallest element of the input iterable according to some comparison function.

Params:

NameTypeAttributeDescription
compare Function

The comparison function to use. This function must be 2-ary. It must return -1, 0, or 1 depending whether the first parameter is, respectively, less than, equal to, or greater than the second parameter.

iterable Iterable

The input iterable.

dflt Object
  • optional
  • default: undefined

The default value to return in the case that the input iterable is empty.

Return:

Object

The smallest element of iterable according to compare.

Example:

min( ( a , b ) => a - b , range( 10 ) ) ; // returns 0
min( ( a , b ) => a - b , range( 0 ) ) ; // returns undefined

public reduce(accumulator: Function, iterable: Iterable, initializer: Object): Object source

Applies the accumulator function iteratively on the last return value of the accumulator and the next value in the input iterable. The initial value is the initializer parameter. If no initial value is given, the first element of the input iterable is used.

Params:

NameTypeAttributeDescription
accumulator Function

The accumulator, a 2-ary function.

iterable Iterable

The input iterable.

initializer Object
  • optional
  • default: undefined

The initial value of the reduction.

Return:

Object

The reduction of the elements of iterable.

Example:

_reduce( ( x , y ) => x + y , range( 10 ) , 0 ) ; // returns 45
_reduce( ( x , y ) => x + y , range( 10 ) , 100 ) ; // returns 145

public some(iterable: Iterable, n: Number): Boolean source

Returns true if at least some of the elements of the input iterable are truthy.

Params:

NameTypeAttributeDescription
iterable Iterable

The input iterable.

n Number

The number of elements that should be truthy.

Return:

Boolean

Returns true if at least n elements of iterable are truthy, false otherwise.

Example:

some( repeat( true ) , 100 ) ; // returns true
some( repeat( false ) , 0 ) ; // returns true
some( repeat( false ) , 10 ) ; // loops forever
some( nrepeat( true , 10 ) , 11 ) ; // returns false

public sum(iterable: Iterable, initializer: Object): Object source

Sums the elements of the input iterable. An optional initializer parameter allows to start the sum of the elements at a chosen value. The default value for the initializer parameter is 0.

Params:

NameTypeAttributeDescription
iterable Iterable

The input iterable.

initializer Object
  • optional
  • default: 0

The initial value of the sum.

Return:

Object

The sum of the initializer with the elements of iterable.

Example:

sum( range( 10 ) ) ; // returns 45
sum( range( 10 ) , 100 ) ; // returns 145

Static Private

private _reduce(accumulator: Function, iterable: Iterable, initializer: Object): Object source

Applies the accumulator function iteratively on the last return value of the accumulator and the next value in the input iterable. The initial value is the initializer parameter.

Params:

NameTypeAttributeDescription
accumulator Function

The accumulator, a 2-ary function.

iterable Iterable

The input iterable.

initializer Object

The initial value of the reduction.

Return:

Object

The reduction of the elements of iterable.

Example:

_reduce( ( x , y ) => x + y , range( 10 ) , 0 ) ; // returns 45
_reduce( ( x , y ) => x + y , range( 10 ) , 100 ) ; // returns 145

private _sum(iterable: Iterable, initializer: Object): Object source

Sums the elements of the input iterable. An optional initializer parameter allows to start the sum of the elements at a chosen value.

Params:

NameTypeAttributeDescription
iterable Iterable

The input iterable.

initializer Object

The initial value of the sum.

Return:

Object

The sum of the initializer with the elements of iterable.

Example:

_sum( range( 10 ) , 0 ) ; // returns 45
_sum( range( 10 ) , 100 ) ; // returns 145