Created
December 5, 2020 11:19
-
-
Save audinue/7ace2c8b375a7e167945bb0fd4d8a587 to your computer and use it in GitHub Desktop.
Simple flow based programming.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { Flow } from '/path/to/flow.js' | |
| let num = new Flow(1) | |
| .map(x => x + 1) | |
| .map(x => x * 2) | |
| .map(x => x / 8) | |
| console.log(num.get()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export class Flow { | |
| constructor (value) { | |
| this._value = value | |
| } | |
| get () { | |
| return this._value | |
| } | |
| map (callback) { | |
| let result = callback(this._value) | |
| if (result instanceof Flow) { | |
| return result | |
| } else { | |
| return new Flow(result) | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment