1.0.2 • Published 7 years ago

yl-while v1.0.2

Weekly downloads
4
License
MIT
Repository
github
Last release
7 years ago

Yl ("while")

:fire: This is a proof-of-concept library and should not be used in production! Because this lib uses something like recursion, it cannot handle very large sets and can easily exceed the stack limit in such cases.

Demonstrates using the Y-combinator to create a function with while-like behavior.

Read more about the Y-combinator in The Mysterious Y-combinator

Use

Pass a function in that takes the current iteration (Number) as its argument. Return false to exit the function early (before the iterations are complete). The value you return from the final iteration will be the exit value. Also supports currying.

Pass a number of times to loop as the second argument. Loop until false is returned by using a negative number.

import Yl from 'yl-while'

// generate a random number over 50
let num = Yl(i => {
  let n = Math.floor(Math.random() * 100)
  return n > 50 ? n : false
}, -1)

License

MIT © Kevin Lanni

1.0.2

7 years ago

1.0.1

9 years ago

1.0.0

9 years ago