Why don't we have a FirstOrNone
method?
#927
Replies: 3 comments 6 replies
-
There is a HeadOrNone extension for IEnumerable: For your case, it will be something like:
|
Beta Was this translation helpful? Give feedback.
1 reply
-
Isn't "Find" what you're looking for?
Returns the first matching element or none.
customers.Find(u => u.FirstName == "Jim")
…On Thu, 14 Oct 2021 at 17:38, tanxeel90 ***@***.***> wrote:
There is a HeadOrNone extension for IEnumerable:
https://github.com/louthy/language-ext/blob/652f38ff754787bcf069ec79c72593d507903ac9/LanguageExt.Core/DataTypes/List/Lst.Extensions.cs#L109
For your case, it will be something like:
customers.Filter(u => u.FirstName == "Jim").HeadOrNone()
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#925 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AA57NKMN53565UUOKK2TQUDUG4ITHANCNFSM5GAE2C4Q>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
MrYossu
-
Both @tanxeel90 and @MartonBoda are correct here. Tanzeel's is a direct answer to what was asked, but Marton's answer is probably the easiest to work with. |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Sorry if this is a stupid question, but you don't get anywhere if you don't ask!
As a slowly reforming OO programmer, I'm trying not to write code like this...
...but rather write code like this...
It seems it would be useful to have a
FirstOrNone
method......as this would enable us to achieve the same without needing our own
GetUser
method...Does LanguageExt have anything like this? If not, is there a good reason why not?
Beta Was this translation helpful? Give feedback.
All reactions