-
Notifications
You must be signed in to change notification settings - Fork 15
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
Should first()
and last()
support a default value?
#132
Comments
The analog in RxJS (because promises) is actually IMO, I think it's a strong add, and anecdotally, I've seen it used frequently |
Back when I did .NET, their enumerables had LastOrDefault and FirstOrDefault, which I thought were clear names and I remember using them often. I do feel wary about getting ahead of iterator helpers for things like this, though. |
Iterator helpers are unlikely to get |
Do you mean "getting ahead" by including these methods at all, in the first place? Separately, I imagine |
Yes. Although if @bakkot thinks we're just not going to have this family for iterators, then maybe it's fine. I think in some ecosystems we'd push for consistency by including even useless methods, as long as they make sense. But oh well.
Sorry, my suggestion was four methods: |
I've thought about this a slight bit more and wanted to capture my thoughts. Potential functionality you might want:
What iterator helpers/ This leads to two choices to get the full functionality:
We don't have to add anything beyond the first bullet point to start. Realistically, unless you are commonly dealing with observables containing From this perspective, I like (1) more. |
Oh yeah, I'm personally very much sold on the path of being consistent with I also like (1), and starting with the first bullet point is my preference for now. That basically means simplifying #131 and #144 to not use Thanks for the feedback, it's much appreciated! |
Just as an initial note to this issue: resolution of this issue is not required for the shipping of either
first()
orlast()
APIs.It came to my attention through looking at the original WPTs for these APIs that there was an expectation of a "default" value for these APIs, in case they complete without emitting any values. RxJS appears to support this too (see https://rxjs.dev/api/operators/first & https://rxjs.dev/api/operators/last).
Personally I don't see this as necessary, since you could easily catch the case where completion happens without any values being emitted, and handle it yourself. But maybe the ergonomics is useful enough to include this? Either way, support for a default value could come at any point in the future too I think.
The text was updated successfully, but these errors were encountered: