Skip to content

Instantly share code, notes, and snippets.

@youaresofunny
Last active December 5, 2018 22:18
Show Gist options
  • Save youaresofunny/67a786f1b6d9d23e8c2d85b641e15fdd to your computer and use it in GitHub Desktop.
Save youaresofunny/67a786f1b6d9d23e8c2d85b641e15fdd to your computer and use it in GitHub Desktop.
function* Stigmerge() {
const stage = {
fun: 'return "Welcome to " + a',
params: ['a'],
payload: ['wtf']
}
while(true) {
if (stage.params === 'stop') return 'Thx for watching';
const worker = new Function(...stage.params, stage.fun)
stage.result = worker(...stage.payload)
const [nextparams, nextfun, nextdata] = yield stage.result;
stage.fun = nextfun;
stage.params = nextparams;
stage.payload = nextdata;
}
}
const stigmerge = Stigmerge()
console.log(stigmerge.next().value);
console.log(stigmerge.next([ ['d', 'a', 'n', 'u'], 'return (d + ( a / n ) * u)', [ 20, 800, 2, 1 ] ]).value)
console.log(stigmerge.next([ ['l', 'a', 'd', 'n', 'o'], 'return (l * a * d * n * o + 300)', [ 1, 2, 3, 4, 5 ] ]).value)
console.log(stigmerge.next(['stop']).value)
// Output:
// Welcome to wtf
// 420
// 420
// Thx for watching
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment