Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/heapwolf/yl
A tiny flow control module that destructures.
https://github.com/heapwolf/yl
Last synced: 5 days ago
JSON representation
A tiny flow control module that destructures.
- Host: GitHub
- URL: https://github.com/heapwolf/yl
- Owner: heapwolf
- Created: 2014-07-22T04:26:35.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-06-15T03:27:00.000Z (over 8 years ago)
- Last Synced: 2024-04-14T22:13:32.273Z (7 months ago)
- Language: JavaScript
- Homepage:
- Size: 8.79 KB
- Stars: 22
- Watchers: 3
- Forks: 5
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# SYNOPSIS
A tiny flow control module that destructures.# CODE
```js
module.exports = f => {if (!f.prototype.throw) return function() {
const args = Array.from(arguments)
return f.bind.apply(f, [null, ...args])
}const gen = f()
~function nextCallback() {
const next = gen.next(Array.from(arguments))
if (!next.done) next.value(nextCallback)
}()
}
```# EXAMPLE
```js
const { run, wrap } = require('yl')
const fs = require('fs')
const assert = require('assert')run(function* () {
const [statError, s] = yield wrap(fs.stat)('./index.js')
if (statError) return console.error(statError)
const [readError, f] = yield wrap(fs.readFile)('./index.js')
assert.equal(f.length, s.size)
})
```Or you could wrap everything initially...
```js
const { run, wrap } = require('yl')
const fs = wrap(require('fs'))
const assert = require('assert')run(function* () {
const [statError, s] = yield fs.stat('./index.js')
const [readError, f] = yield fs.readFile('./index.js')assert.equal(f.length, s.size)
})
```