-
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
replace mergeMap with switchMap, fixes #27 #60
base: master
Are you sure you want to change the base?
Conversation
I'm not sure it's safe to assume that |
This is not about running sequentially vs parallel. If it were so, we would be suggesting to replace |
if we had to pick a default, (Ultimately I don't mind what we do, personally I'm not using |
Using the RxJS operators directly kind of defeats my purpose for using this library, i.e. the convenience it offers for But anyway, good argument about switchMap, but then I would argue that So, what would the API for various operators look like? one method for each operator? Something like |
At Unsplash we've defined operators for each type using the same names as the built-in
export const switchMap = <E, A, B>(
fn: (a: A) => ObservableEither<E, B>,
): Rx.OperatorFunction<E.Either<E, A>, E.Either<E, B>> => (t$) =>
pipe(t$, Rx.switchMap(E.fold(left, fn)));
export const switchMap = <E, A, B>(
fn: (a: A) => ObservableRemoteData<E, B>,
): Rx.OperatorFunction<RemoteData.RemoteData<E, A>, RemoteData.RemoteData<E, B>> => (t$) =>
pipe(
t$,
Rx.switchMap((remoteData) =>
RemoteData.isSuccess(remoteData) ? fn(remoteData.value) : Rx.of(remoteData),
),
); We could prefix those names with |
@OliverJAsh I mean try to support mappers with |
This solves the original problem reported in #27.
As for the suggestion @OliverJAsh that we should be able to specify which merge strategy to use, sounds great, but can we implement this in a subsequent discussion and PR?