SkillAgentSearch skills...

Yl

A tiny flow control module that destructures.

Install / Use

/learn @heapwolf/Yl
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

SYNOPSIS

A tiny flow control module that destructures.

CODE

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

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...

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)
})
View on GitHub
GitHub Stars22
CategoryDevelopment
Updated4y ago
Forks5

Languages

JavaScript

Security Score

60/100

Audited on Jun 14, 2021

No findings