rxjs - Zipping value with corresponging flatMap result -
let's have stream of files filesstream
, function uploadfile
returns stream of 1 value (rx.observable.frompromise(...)). files on stream can uploaded via simple flatmap
:
filesstream.flatmap(uploadfile)
what need zip files filesstream
corresponding responses uploadfile
:
zippedstream.subscribe( (file, response) => console.log("file " + file.name + " uploaded: " + response.message) )
i've come quite messy approach work
var zipppedstream = filesstream.flatmap( (file) => uploadfile(file).zip(rx.observable.just(file), (r, f) => [r, f]) )
but don't since need unpack two-valued array in subscribe
, looks heavy. how or i'm missing something?
you can bypass using zip
, use flatmap
overload instead accomplish want here
let zippedstream = filestream.flatmap( (file) => uploadfile(file), (file, uploaded) => [file, uploaded]); zippedstream.subscribe( ([file, response]) => console.log("file " + file.name + " uploaded: " + response.message));
Comments
Post a Comment