Function
Static Public Summary | ||
public |
Returns true if all of the elements of the input iterable are truthy. |
|
public |
Returns true if any of the elements of the input iterable is truthy. |
|
public |
Returns the largest element of the input iterable according to some comparison function. |
|
public |
Returns the smallest element of the input iterable according to some comparison function. |
|
public |
Applies the accumulator function iteratively on the last return value of the accumulator and the next value in the input iterable. |
|
public |
Returns true if at least some of the elements of the input iterable are truthy. |
|
public |
Sums the elements of the input iterable. |
Static Private Summary | ||
private |
Applies the accumulator function iteratively on the last return value of the accumulator and the next value in the input iterable. |
|
private |
Sums the elements of the input iterable. |
Static Public
public all(iterable: Iterable): Boolean source
import all from '@iterable-iterator/reduce/src/all.js'
Returns true if all of the elements of the input iterable are truthy.
Params:
Name | Type | Attribute | Description |
iterable | Iterable | The input iterable. |
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
import any from '@iterable-iterator/reduce/src/any.js'
Returns true if any of the elements of the input iterable is truthy.
Params:
Name | Type | Attribute | Description |
iterable | Iterable | The input iterable. |
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
import max from '@iterable-iterator/reduce/src/max.js'
Returns the largest element of the input iterable according to some comparison function.
Params:
Name | Type | Attribute | Description |
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 |
|
The default value to return in the case that the input iterable is empty. |
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
import min from '@iterable-iterator/reduce/src/min.js'
Returns the smallest element of the input iterable according to some comparison function.
Params:
Name | Type | Attribute | Description |
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 |
|
The default value to return in the case that the input iterable is empty. |
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
import reduce from '@iterable-iterator/reduce/src/reduce.js'
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.
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
import some from '@iterable-iterator/reduce/src/some.js'
Returns true if at least some of the elements of the input iterable are truthy.
Params:
Name | Type | Attribute | Description |
iterable | Iterable | The input iterable. |
|
n | Number | The number of elements that should be truthy. |
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
import sum from '@iterable-iterator/reduce/src/sum.js'
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:
Name | Type | Attribute | Description |
iterable | Iterable | The input iterable. |
|
initializer | Object |
|
The initial value of the sum. |
Example:
sum( range( 10 ) ) ; // returns 45
sum( range( 10 ) , 100 ) ; // returns 145
Static Private
private _reduce(accumulator: Function, iterable: Iterable, initializer: Object): Object source
import _reduce from '@iterable-iterator/reduce/src/_reduce.js'
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.
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
import _sum from '@iterable-iterator/reduce/src/_sum.js'
Sums the elements of the input iterable. An optional initializer parameter allows to start the sum of the elements at a chosen value.
Params:
Name | Type | Attribute | Description |
iterable | Iterable | The input iterable. |
|
initializer | Object | The initial value of the sum. |
Example:
_sum( range( 10 ) , 0 ) ; // returns 45
_sum( range( 10 ) , 100 ) ; // returns 145