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

Suggestion: provide alternatives to operators which throw exceptions / emit errors #55

Open
OliverJAsh opened this issue Feb 12, 2021 · 2 comments

Comments

@OliverJAsh
Copy link
Contributor

OliverJAsh commented Feb 12, 2021

🚀 Feature request

Current Behavior

In RxJS, some operators are known to throw exceptions intentionally, in non-exceptional circumstances.

For example, the first operator will throw an EmptyError if the observable completes after having emitted no items (an empty observable). https://rxjs-dev.firebaseapp.com/api/operators/first

Other operators which throw: last, single, and the forthcoming lastValueFrom/firstValueFrom (RxJS 7).

Desired Behavior

Operators which don't throw.

Suggested Solution

For example, this library could provide its own first operator which would return Observable<Option<T>>. If the observable is empty, the observable would emit none instead of throwing an exception / emitting an error.

@mlegenhausen
Copy link
Collaborator

mlegenhausen commented Feb 12, 2021

Sounds good. We could name them analog to the Array methods head and tail.

@OliverJAsh
Copy link
Contributor Author

OliverJAsh commented Feb 12, 2021

Here's another one: fromFetch. If the user loses connectivity by the time you subscribe to the observable, fetch will reject and thereby the observable will emit an error.

Here's a wrapper we've been using at Unsplash around RxJS' fromFetch.

  • never throws
  • returns ObservableEither<FetchError | ResponseJsonParseError, Either.Json>

https://stackblitz.com/edit/fp-ts-rxjs-fromfetch?file=index.ts

Update: https://github.com/unsplash/request-frp

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