Whatever happened to `Observable.transduce` in RxJS v5+?
RxJS v4 used to have an Observable.transduce
method which took a transducer. This allowed the use of library-independent transducer operators which had major performance benefits in the past.
Sources
- https://github.com/Reactive-Extensions/RxJS/blob/master/doc/api/core/operators/transduce.md
- https://github.com/Reactive-Extensions/RxJS/blob/master/doc/gettingstarted/transducers.md
- https://medium.com/front-end-hacking/rxjs-transducers-vs-method-chaining-performance-87561cf4ce65
- https://github.com/ReactiveX/rxjs/pull/1323
RxJS v5.5 and v6 have pipeable operators and v6 removed method chaining. Because of this, I assumed RxJS operators were standard transducers. Looking through the source code, that doesn't seem to be the case.
RxJS v6 operators function like a transducer where each value is passed entirely through the chain before the next value goes through, but RxJS v6 operators aren't using the standard transducer methods I've seen in other libraries meaning, I don't think they're portable.
The whole thing about transducers is they don't know anything about the collection itself. Instead of writing 100 operators specifically for observables, you could write 100 operators universally able to be applied to any collection or stream type.
Is .pipe
unanimous with .transduce
or was this method completely removed in RxJS v5?
rxjs method-chaining pipelining transducer
add a comment |
RxJS v4 used to have an Observable.transduce
method which took a transducer. This allowed the use of library-independent transducer operators which had major performance benefits in the past.
Sources
- https://github.com/Reactive-Extensions/RxJS/blob/master/doc/api/core/operators/transduce.md
- https://github.com/Reactive-Extensions/RxJS/blob/master/doc/gettingstarted/transducers.md
- https://medium.com/front-end-hacking/rxjs-transducers-vs-method-chaining-performance-87561cf4ce65
- https://github.com/ReactiveX/rxjs/pull/1323
RxJS v5.5 and v6 have pipeable operators and v6 removed method chaining. Because of this, I assumed RxJS operators were standard transducers. Looking through the source code, that doesn't seem to be the case.
RxJS v6 operators function like a transducer where each value is passed entirely through the chain before the next value goes through, but RxJS v6 operators aren't using the standard transducer methods I've seen in other libraries meaning, I don't think they're portable.
The whole thing about transducers is they don't know anything about the collection itself. Instead of writing 100 operators specifically for observables, you could write 100 operators universally able to be applied to any collection or stream type.
Is .pipe
unanimous with .transduce
or was this method completely removed in RxJS v5?
rxjs method-chaining pipelining transducer
add a comment |
RxJS v4 used to have an Observable.transduce
method which took a transducer. This allowed the use of library-independent transducer operators which had major performance benefits in the past.
Sources
- https://github.com/Reactive-Extensions/RxJS/blob/master/doc/api/core/operators/transduce.md
- https://github.com/Reactive-Extensions/RxJS/blob/master/doc/gettingstarted/transducers.md
- https://medium.com/front-end-hacking/rxjs-transducers-vs-method-chaining-performance-87561cf4ce65
- https://github.com/ReactiveX/rxjs/pull/1323
RxJS v5.5 and v6 have pipeable operators and v6 removed method chaining. Because of this, I assumed RxJS operators were standard transducers. Looking through the source code, that doesn't seem to be the case.
RxJS v6 operators function like a transducer where each value is passed entirely through the chain before the next value goes through, but RxJS v6 operators aren't using the standard transducer methods I've seen in other libraries meaning, I don't think they're portable.
The whole thing about transducers is they don't know anything about the collection itself. Instead of writing 100 operators specifically for observables, you could write 100 operators universally able to be applied to any collection or stream type.
Is .pipe
unanimous with .transduce
or was this method completely removed in RxJS v5?
rxjs method-chaining pipelining transducer
RxJS v4 used to have an Observable.transduce
method which took a transducer. This allowed the use of library-independent transducer operators which had major performance benefits in the past.
Sources
- https://github.com/Reactive-Extensions/RxJS/blob/master/doc/api/core/operators/transduce.md
- https://github.com/Reactive-Extensions/RxJS/blob/master/doc/gettingstarted/transducers.md
- https://medium.com/front-end-hacking/rxjs-transducers-vs-method-chaining-performance-87561cf4ce65
- https://github.com/ReactiveX/rxjs/pull/1323
RxJS v5.5 and v6 have pipeable operators and v6 removed method chaining. Because of this, I assumed RxJS operators were standard transducers. Looking through the source code, that doesn't seem to be the case.
RxJS v6 operators function like a transducer where each value is passed entirely through the chain before the next value goes through, but RxJS v6 operators aren't using the standard transducer methods I've seen in other libraries meaning, I don't think they're portable.
The whole thing about transducers is they don't know anything about the collection itself. Instead of writing 100 operators specifically for observables, you could write 100 operators universally able to be applied to any collection or stream type.
Is .pipe
unanimous with .transduce
or was this method completely removed in RxJS v5?
rxjs method-chaining pipelining transducer
rxjs method-chaining pipelining transducer
edited Nov 25 '18 at 20:38
Sawtaytoes
asked Nov 23 '18 at 14:59
SawtaytoesSawtaytoes
2,02711732
2,02711732
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
I had the exact same question and could not find the answer anywhere. Yes you can pipe
, but I believe that would create intermediary observables for each operator. I don't know for sure though, it would be about reading the code.
So I came up with my own transduce
operator :
function transformForObserver(o) {
return {
"@@transducer/init": function() {
return o;
},
"@@transducer/step": function(obs, input) {
return obs.next(input);
},
"@@transducer/result": function(obs) {
return obs.complete();
}
};
}
const transduce = (obs, transducer) => {
const xform = transducer(transformForObserver);
return Observable.create(o => {
return obs.subscribe({
next: x => {
const res = tryCatch(
xform["@@transducer/step"],
err => {
console.error(`Error occurred in transducer/step!`, err);
return err;
}
)(xform, o, x);
if (res instanceof Error) { o.error(res); }
},
error: err => {
console.error(`Error occurred in observable passed to Rx transduce fn!`, err);
o.error(err);
},
complete: () => {o.complete();}
});
});
}
Haven't tested it yet, will post soon about it if there is interest.
Update : I forked jslongser's tranducers library and included such transducers in it. Fork is https://github.com/brucou/transducers.js, and the function is transduceLazyObservable
. Cf. tests for example of use.
It'll be nice to expand compatibility with other transducer libraries.
– Sawtaytoes
Dec 31 '18 at 3:48
Don't know what you mean by that. This follows the transducer protocol if that is what you were referring to.
– user3743222
Dec 31 '18 at 3:50
Yes. So it'll allow using other libraries along with it!
– Sawtaytoes
Dec 31 '18 at 3:57
by curiosity, how good were the performance benefits? The transducers available for javascript are pretty limited. I was looking forstartWith
for example and I am writing one.
– user3743222
Dec 31 '18 at 3:59
1
tested the observable transducer and added to a library. You can have a look. From that function, you should be able to put it on a prototype or use it as is. Star the repository it works and leave an issue there if it does not. I only tested locally.
– user3743222
Jan 1 at 4:46
|
show 2 more comments
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53448936%2fwhatever-happened-to-observable-transduce-in-rxjs-v5%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I had the exact same question and could not find the answer anywhere. Yes you can pipe
, but I believe that would create intermediary observables for each operator. I don't know for sure though, it would be about reading the code.
So I came up with my own transduce
operator :
function transformForObserver(o) {
return {
"@@transducer/init": function() {
return o;
},
"@@transducer/step": function(obs, input) {
return obs.next(input);
},
"@@transducer/result": function(obs) {
return obs.complete();
}
};
}
const transduce = (obs, transducer) => {
const xform = transducer(transformForObserver);
return Observable.create(o => {
return obs.subscribe({
next: x => {
const res = tryCatch(
xform["@@transducer/step"],
err => {
console.error(`Error occurred in transducer/step!`, err);
return err;
}
)(xform, o, x);
if (res instanceof Error) { o.error(res); }
},
error: err => {
console.error(`Error occurred in observable passed to Rx transduce fn!`, err);
o.error(err);
},
complete: () => {o.complete();}
});
});
}
Haven't tested it yet, will post soon about it if there is interest.
Update : I forked jslongser's tranducers library and included such transducers in it. Fork is https://github.com/brucou/transducers.js, and the function is transduceLazyObservable
. Cf. tests for example of use.
It'll be nice to expand compatibility with other transducer libraries.
– Sawtaytoes
Dec 31 '18 at 3:48
Don't know what you mean by that. This follows the transducer protocol if that is what you were referring to.
– user3743222
Dec 31 '18 at 3:50
Yes. So it'll allow using other libraries along with it!
– Sawtaytoes
Dec 31 '18 at 3:57
by curiosity, how good were the performance benefits? The transducers available for javascript are pretty limited. I was looking forstartWith
for example and I am writing one.
– user3743222
Dec 31 '18 at 3:59
1
tested the observable transducer and added to a library. You can have a look. From that function, you should be able to put it on a prototype or use it as is. Star the repository it works and leave an issue there if it does not. I only tested locally.
– user3743222
Jan 1 at 4:46
|
show 2 more comments
I had the exact same question and could not find the answer anywhere. Yes you can pipe
, but I believe that would create intermediary observables for each operator. I don't know for sure though, it would be about reading the code.
So I came up with my own transduce
operator :
function transformForObserver(o) {
return {
"@@transducer/init": function() {
return o;
},
"@@transducer/step": function(obs, input) {
return obs.next(input);
},
"@@transducer/result": function(obs) {
return obs.complete();
}
};
}
const transduce = (obs, transducer) => {
const xform = transducer(transformForObserver);
return Observable.create(o => {
return obs.subscribe({
next: x => {
const res = tryCatch(
xform["@@transducer/step"],
err => {
console.error(`Error occurred in transducer/step!`, err);
return err;
}
)(xform, o, x);
if (res instanceof Error) { o.error(res); }
},
error: err => {
console.error(`Error occurred in observable passed to Rx transduce fn!`, err);
o.error(err);
},
complete: () => {o.complete();}
});
});
}
Haven't tested it yet, will post soon about it if there is interest.
Update : I forked jslongser's tranducers library and included such transducers in it. Fork is https://github.com/brucou/transducers.js, and the function is transduceLazyObservable
. Cf. tests for example of use.
It'll be nice to expand compatibility with other transducer libraries.
– Sawtaytoes
Dec 31 '18 at 3:48
Don't know what you mean by that. This follows the transducer protocol if that is what you were referring to.
– user3743222
Dec 31 '18 at 3:50
Yes. So it'll allow using other libraries along with it!
– Sawtaytoes
Dec 31 '18 at 3:57
by curiosity, how good were the performance benefits? The transducers available for javascript are pretty limited. I was looking forstartWith
for example and I am writing one.
– user3743222
Dec 31 '18 at 3:59
1
tested the observable transducer and added to a library. You can have a look. From that function, you should be able to put it on a prototype or use it as is. Star the repository it works and leave an issue there if it does not. I only tested locally.
– user3743222
Jan 1 at 4:46
|
show 2 more comments
I had the exact same question and could not find the answer anywhere. Yes you can pipe
, but I believe that would create intermediary observables for each operator. I don't know for sure though, it would be about reading the code.
So I came up with my own transduce
operator :
function transformForObserver(o) {
return {
"@@transducer/init": function() {
return o;
},
"@@transducer/step": function(obs, input) {
return obs.next(input);
},
"@@transducer/result": function(obs) {
return obs.complete();
}
};
}
const transduce = (obs, transducer) => {
const xform = transducer(transformForObserver);
return Observable.create(o => {
return obs.subscribe({
next: x => {
const res = tryCatch(
xform["@@transducer/step"],
err => {
console.error(`Error occurred in transducer/step!`, err);
return err;
}
)(xform, o, x);
if (res instanceof Error) { o.error(res); }
},
error: err => {
console.error(`Error occurred in observable passed to Rx transduce fn!`, err);
o.error(err);
},
complete: () => {o.complete();}
});
});
}
Haven't tested it yet, will post soon about it if there is interest.
Update : I forked jslongser's tranducers library and included such transducers in it. Fork is https://github.com/brucou/transducers.js, and the function is transduceLazyObservable
. Cf. tests for example of use.
I had the exact same question and could not find the answer anywhere. Yes you can pipe
, but I believe that would create intermediary observables for each operator. I don't know for sure though, it would be about reading the code.
So I came up with my own transduce
operator :
function transformForObserver(o) {
return {
"@@transducer/init": function() {
return o;
},
"@@transducer/step": function(obs, input) {
return obs.next(input);
},
"@@transducer/result": function(obs) {
return obs.complete();
}
};
}
const transduce = (obs, transducer) => {
const xform = transducer(transformForObserver);
return Observable.create(o => {
return obs.subscribe({
next: x => {
const res = tryCatch(
xform["@@transducer/step"],
err => {
console.error(`Error occurred in transducer/step!`, err);
return err;
}
)(xform, o, x);
if (res instanceof Error) { o.error(res); }
},
error: err => {
console.error(`Error occurred in observable passed to Rx transduce fn!`, err);
o.error(err);
},
complete: () => {o.complete();}
});
});
}
Haven't tested it yet, will post soon about it if there is interest.
Update : I forked jslongser's tranducers library and included such transducers in it. Fork is https://github.com/brucou/transducers.js, and the function is transduceLazyObservable
. Cf. tests for example of use.
edited Jan 1 at 4:45
answered Dec 31 '18 at 3:40
user3743222user3743222
13.2k44962
13.2k44962
It'll be nice to expand compatibility with other transducer libraries.
– Sawtaytoes
Dec 31 '18 at 3:48
Don't know what you mean by that. This follows the transducer protocol if that is what you were referring to.
– user3743222
Dec 31 '18 at 3:50
Yes. So it'll allow using other libraries along with it!
– Sawtaytoes
Dec 31 '18 at 3:57
by curiosity, how good were the performance benefits? The transducers available for javascript are pretty limited. I was looking forstartWith
for example and I am writing one.
– user3743222
Dec 31 '18 at 3:59
1
tested the observable transducer and added to a library. You can have a look. From that function, you should be able to put it on a prototype or use it as is. Star the repository it works and leave an issue there if it does not. I only tested locally.
– user3743222
Jan 1 at 4:46
|
show 2 more comments
It'll be nice to expand compatibility with other transducer libraries.
– Sawtaytoes
Dec 31 '18 at 3:48
Don't know what you mean by that. This follows the transducer protocol if that is what you were referring to.
– user3743222
Dec 31 '18 at 3:50
Yes. So it'll allow using other libraries along with it!
– Sawtaytoes
Dec 31 '18 at 3:57
by curiosity, how good were the performance benefits? The transducers available for javascript are pretty limited. I was looking forstartWith
for example and I am writing one.
– user3743222
Dec 31 '18 at 3:59
1
tested the observable transducer and added to a library. You can have a look. From that function, you should be able to put it on a prototype or use it as is. Star the repository it works and leave an issue there if it does not. I only tested locally.
– user3743222
Jan 1 at 4:46
It'll be nice to expand compatibility with other transducer libraries.
– Sawtaytoes
Dec 31 '18 at 3:48
It'll be nice to expand compatibility with other transducer libraries.
– Sawtaytoes
Dec 31 '18 at 3:48
Don't know what you mean by that. This follows the transducer protocol if that is what you were referring to.
– user3743222
Dec 31 '18 at 3:50
Don't know what you mean by that. This follows the transducer protocol if that is what you were referring to.
– user3743222
Dec 31 '18 at 3:50
Yes. So it'll allow using other libraries along with it!
– Sawtaytoes
Dec 31 '18 at 3:57
Yes. So it'll allow using other libraries along with it!
– Sawtaytoes
Dec 31 '18 at 3:57
by curiosity, how good were the performance benefits? The transducers available for javascript are pretty limited. I was looking for
startWith
for example and I am writing one.– user3743222
Dec 31 '18 at 3:59
by curiosity, how good were the performance benefits? The transducers available for javascript are pretty limited. I was looking for
startWith
for example and I am writing one.– user3743222
Dec 31 '18 at 3:59
1
1
tested the observable transducer and added to a library. You can have a look. From that function, you should be able to put it on a prototype or use it as is. Star the repository it works and leave an issue there if it does not. I only tested locally.
– user3743222
Jan 1 at 4:46
tested the observable transducer and added to a library. You can have a look. From that function, you should be able to put it on a prototype or use it as is. Star the repository it works and leave an issue there if it does not. I only tested locally.
– user3743222
Jan 1 at 4:46
|
show 2 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53448936%2fwhatever-happened-to-observable-transduce-in-rxjs-v5%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown