Skip to content

Instantly share code, notes, and snippets.

@adz5a
Last active Jul 27, 2017
Embed
What would you like to do?
stream-fold
"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