Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/therealklanni/yl
Yl
https://github.com/therealklanni/yl
Last synced: 2 days ago
JSON representation
Yl
- Host: GitHub
- URL: https://github.com/therealklanni/yl
- Owner: therealklanni
- Created: 2015-08-11T04:47:41.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-04-21T23:13:19.000Z (over 7 years ago)
- Last Synced: 2024-10-31T11:58:33.306Z (20 days ago)
- Language: JavaScript
- Homepage:
- Size: 3.91 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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](https://medium.com/@therealklanni/the-mysterious-y-combinator-e824bebf8c96)**
## 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.
```js
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