Options
All
  • Public
  • Public/Protected
  • All
Menu

External module "iter/replicate-by/docs/types/index.d"

Index

Type aliases

Binary

Binary: (value: any, index: number) => number

Returns the number of times an iterated value should be replicated.

param

iterated value

param

source iteration index (zero-based)

returns

number of times an iterated value should be replicated

Type declaration

    • (value: any, index: number): number
    • Parameters

      • value: any
      • index: number

      Returns number

Callback

Callback: Nullary | Unary | Binary | Ternary

Returns the number of times an iterated value should be replicated.

param

iterated value

param

source iteration index (zero-based)

param

iteration index (zero-based)

returns

number of times an iterated value should be replicated

Iterator

Iterator: Iter | IterableIterator

Nullary

Nullary: () => number

Returns the number of times an iterated value should be replicated.

returns

number of times an iterated value should be replicated

Type declaration

    • (): number
    • Returns number

Ternary

Ternary: (value: any, index: number, n: number) => number

Returns the number of times an iterated value should be replicated.

param

iterated value

param

source iteration index (zero-based)

param

iteration index (zero-based)

returns

number of times an iterated value should be replicated

Type declaration

    • (value: any, index: number, n: number): number
    • Parameters

      • value: any
      • index: number
      • n: number

      Returns number

Unary

Unary: (value: any) => number

Returns the number of times an iterated value should be replicated.

param

iterated value

returns

number of times an iterated value should be replicated

Type declaration

    • (value: any): number
    • Parameters

      • value: any

      Returns number

Functions

Export assignment iterReplicateBy

  • Returns an iterator which invokes a function for each iterated value.

    Notes

    • The callback function is provided three arguments:

      • value: iterated value
      • index: source iteration index (zero-based)
      • n: iteration index (zero-based)
    • The callback function is invoked once per iterated value of the provided iterator.

    • The callback function must return an integer value. If the return value is less than or equal to zero, the returned iterator skips an iterated value and invokes the callback for the next iterated value of the provided iterator.

    • If an environment supports Symbol.iterator and a provided iterator is iterable, the returned iterator is iterable.

    Parameters

    • iterator: Iterator

      input iterator

    • fcn: Callback

      callback function which returns the number of times an iterated value should be replicated

    • Optional thisArg: any

      execution context

    Returns Iterator

    iterator

    Example

    var array2iterator = require( `@stdlib/array/to-iterator` );
    
    function fcn( v, i ) {
        return i + 1;
    }
    
    var src = array2iterator( [ 1, 2, 3, 4 ] );
    var iter = iterReplicateBy( src, fcn );
    
    var v = iter.next().value;
    // returns 1
    
    v = iter.next().value;
    // returns 2
    
    v = iter.next().value;
    // returns 2
    
    v = iter.next().value;
    // returns 3
    
    v = iter.next().value;
    // returns 3
    
    v = iter.next().value;
    // returns 3