Skip to content

Instantly share code, notes, and snippets.

@FbN
Created November 1, 2019 13:18
Show Gist options
  • Save FbN/59863cfb6f60ecc671ee2d3250c0528a to your computer and use it in GitHub Desktop.
Save FbN/59863cfb6f60ecc671ee2d3250c0528a to your computer and use it in GitHub Desktop.
xstream version
function todoList (deferred) {
const ping$ = xs.create({
start: function (listener) {
setTimeout(() => {
;[...Array(config.iterations).keys()].forEach(i =>
listener.next(i)
)
}, 0)
},
stop: function () {}
})
const todo$ = ping$.map(todo)
const old$ = todo$.filter(todo => todo.id % 4 === 0).startWith({})
const sample$ = sampleCombine(old$)(todo$).map(([last, old]) => ({
...last,
old
}))
const list$ = sample$.fold((list, item) => [...list, item], [])
const end$ = list$.filter(list => list.length === config.iterations).take(1)
return end$.map(res => deferred.resolve(res))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment