iterate-function
v1.1.1
Published
Repeatedly apply a function.
Downloads
2
Readme
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