Last active
April 24, 2016 20:41
-
-
Save fudini/38efdd4dc9f243402529a1cf9510e3d3 to your computer and use it in GitHub Desktop.
Recursive Rx
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
const pageSize = 10 | |
const getPage = page => { | |
const pageContent = _.range(0, pageSize).map(v => v + (page * pageSize)) | |
if(page == 9) { | |
return Rx.Observable.just({ | |
nextPage: null, | |
page: pageContent | |
}) | |
} | |
return Rx.Observable.just({ | |
nextPage: page + 1, | |
page: pageContent | |
}) | |
} | |
getPage(0) | |
.expand(result => { | |
if(!result.nextPage) { | |
return Rx.Observable.empty() | |
} | |
return getPage(result.nextPage) | |
}) | |
.scan((acc, page) => { | |
return acc.concat(page.page) | |
}, []) | |
.last() | |
.subscribe(x => console.log(x)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment