-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Chain implementation causes memory leaks #27
Comments
@gcanti What do you think? |
Using |
That's what I asked :) Ok, I'll try to add some tests using |
So I've added tests for |
There's a Scala implementation of Rx observables here: https://github.com/OlivierBlanvillain/monadic-html |
Also the author implements Semigroup (by proving only associativity unlike Alt which needs distributivity) using |
I came here because I wanted to use On the |
@OliverJAsh I don't think we need to implement them specifically, unless they're not pipeable. We can just use them in the |
They should be pipeable, I think the tricky thing is that they aren't transformed with Either, so the types don't quite match up: const b = pipe(
from([1, 2, 3, 4]),
_.rightObservable,
switchMap((e: E.Either<unknown, number>) => ...), // only accepts an either as input
) import * as E from 'fp-ts/Either'
const b = pipe(
from([1, 2, 3, 4]),
_.rightObservable,
switchMap(E.chain((a): E.Either<unknown, number> => ...)), // won't accept an ObservableEither as Output
) I believe for the proper behavior you have to re-implement EitherT.chain: const b = pipe(
from([1, 2, 3, 4]),
_.rightObservable,
switchMap((e) => (E.isLeft(e) ? of(E.left(e.left)) : ... )),
) I agree with @OliverJAsh that operators would be helpful, or maybe different applicative instances (similar to taskSeq) (which has been discussed before) |
I've been avoiding |
@OliverJAsh during my vacations (where else 😉) I had the idea of splitting up the Monad instances in four different packages These packages will each export their own import * as R from 'fp-ts-rxjs/Observable'
import * as Rm from 'fp-ts-rxjs/Observable/Merge'
import * as Rc from 'fp-ts-rxjs/Observable/Concat'
import * as Rs from 'fp-ts-rxjs/Observable/Switch'
import * as Re from 'fp-ts-rxjs/Observable/Exhaust'
pipe(
Rm.bind('a', () => R.of(1)), // uses mergeMap
Rs.bind('b', () => R.of(2)), // uses switchMap
Re.bind('c', () => R.of(3)) // uses exhaustMap
Rc.bind('d', () => R.of(4)) // uses concatMap
) What do you think? |
That's a good idea! |
I could also image that the |
Hi,
Currently
chain
is implemented usingmergeMap
which is known to not unsubscribe from the passed observable on source emit. It's recommended to useswitchMap
in such cases. IsmergeMap
used intentionally here (for some laws to hold) or it can be replaced withswitchMap
?The text was updated successfully, but these errors were encountered: