ReactiveX / ReactiveX/rxjs

`find` is a little broken, IMO, and we have work to do with similar operators.

Open
#6,117 4 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
31.7k
Forks
3k
PR merge metrics
No merged PRs in 30d

Description

The current implementation of find is basically first(fn, undefined). It seems like if you don't "find" the item, it should just complete. Otherwise, I'm not sure what differentiates this operate from first and we can probably remove it.

I understand that the current behavior was meant to model Array.prototype.find, but that's a bit different, because it returns T and not T[]... where our find on Observable<T> returns Observable<T | undefined>, which doesn't make sense to me. What if we're literally trying to find undefined? How do I know I found it?

of(1, 2, 3, 4, undefined, 5, 6, 7).pipe(find(x => x === undefined));

I think our options are:

  1. Deprecate and remove find and show people first(fn, undefined) instead.
  2. Fix find so that it returns EMPTY if it doesn't "find" anything. Which is a breaking change for some folks for sure.

I'm completely on the fence with this. And maybe we just punt until version 8.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the current find operator and its relationship to first(fn, undefined), then run through the provided example that searches for undefined. The work is complete only after the project decides between removing or deprecating find and changing it to complete with EMPTY, with the resulting Observable behavior clearly defined.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.