Skip to content
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

fold and foldTask? #13

Open
pbadenski opened this issue Aug 7, 2019 · 1 comment
Open

fold and foldTask? #13

pbadenski opened this issue Aug 7, 2019 · 1 comment

Comments

@pbadenski
Copy link

These can be easily written by a user, but I was wondering if it's worth adding to this library (or least have a section for recipes?). At least in our project these use cases are quite common.

const fold = <T, O extends ObservableInput<T>> (obs: Observable<O>) =>
  observable.chain<O, T>(t => from(t))(obs);

const foldTask = <T> (obs: Observable<task.Task<T>>) => {
  observable.chain<task.Task<T>, T>(t => from(t()))(obs);
};
@waynevanson
Copy link
Contributor

waynevanson commented Oct 20, 2020

const fold = <T, O extends ObservableInput<T>> (obs: Observable<O>) =>
  observable.chain<O, T>(t => from(t))(obs);

@pbadenski fold Is an unsafe cast. Perhaps just use map(a => a as Observable<T>).

fromTask and fromObservable were added by #20 and #21.

foldTask is now just chain(fromTask), which seems like it should just be done inline, instead of being exposed as a helper function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants