Last active
July 27, 2017 14:50
-
-
Save adz5a/1f28dacbf6e2c9a97c8466b9c179e2ea to your computer and use it in GitHub Desktop.
stream-fold
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
"use strict"; | |
const xs = require("xstream").default; | |
const fromDiagram = require("xstream/extra/fromDiagram").default; | |
const delay = require("xstream/extra/delay").default; | |
const get = () => { | |
console.log("called"); | |
return Promise.resolve("lol"); | |
}; | |
const process = () => { | |
const input$ = fromDiagram("a----b----c----d|"); | |
return xs.of(1) | |
.map(value => { | |
return input$ | |
.fold( ( stream$, _ ) => { | |
console.log("folding" , _); | |
return stream$ | |
.last() | |
.map( value => { | |
return get(); | |
}) | |
.map(xs.fromPromise) | |
.flatten() | |
.take(1); | |
}, xs.of(value) ) | |
.flatten(); | |
}) | |
.flatten(); | |
}; | |
process().addListener({ | |
next ( value ) { | |
console.log("received ", value); | |
}, | |
complete () {}, | |
error () {} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment