-
Notifications
You must be signed in to change notification settings - Fork 84
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
Confusing singleWhereOrNull
extension method
#294
Comments
I can see how the I do think that |
Chiming in that the implementation of this method is confusing, for the reasons discussed here. I expect a |
Do you expect The |
Not if the suffix is
Understood, that is what it does. It's not what I expected, and I'm glad I read the docs. What you call I agree with jaripekkala that the behavior of this method is confusing, and I think it's likely that others are wrongly expecting |
https://github.com/dart-lang/collection/blob/v1.17.2/lib/src/iterable_extensions.dart#L296-L304
My proposal: Deprecate and delete
singleWhereOrNull
, and introduce more clear methodsReasoning:
Many use the
singleWhere
method as replacement tofirstWhere
when the list should not contain more than one matching value, in cases when the logic would not work if code somewhere later changes in way that there are multiple matching values, so throwing error would make sense (developer need to go and handle the case).But when also no matching value is acceptable, developer can mistakenly use
singleWhereOrNull
and have different behaviour than intended. These cases are not so commonly unit tested, as these cases are preventing mistakes in the future.The text was updated successfully, but these errors were encountered: