iterate-function

1.1.1 • Public • Published

iterate-function

Repeatedly apply a function.

iterate(limit, inital_value, func)
 
  // or:
 
iterate(limit, func)

func gets passed two arguments:

iterate(limit, inital_value, func(index, applied_value) { do_stuff(); })

'index' is the current index of the loop. 'applied_value' is the return value of that function for the previous iteration.

Simple example:

  iterate(3, function(i) { console.log(i) })
  > 0
  > 1
  > 2

Using the applied value to get the powers of 2:

power = iterate(4, 1, function(i, applied) { return applied * 2 });
> 16

see similar: http://hackage.haskell.org/packages/archive/base/latest/doc/html/Prelude.html#v:iterate

Package Sidebar

Install

npm i iterate-function

Weekly Downloads

2

Version

1.1.1

License

BSD

Last publish

Collaborators

  • jayrbolton
  • the_swerve