Skip to content

Instantly share code, notes, and snippets.

@audinue
Created December 5, 2020 11:19
Show Gist options
  • Select an option

  • Save audinue/7ace2c8b375a7e167945bb0fd4d8a587 to your computer and use it in GitHub Desktop.

Select an option

Save audinue/7ace2c8b375a7e167945bb0fd4d8a587 to your computer and use it in GitHub Desktop.
Simple flow based programming.
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())
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