Add Func<> equivalent to Execute Action<> Maybe extension#10
Add Func<> equivalent to Execute Action<> Maybe extension#10laurence79 wants to merge 1 commit intovkhorikov:masterfrom
Conversation
|
Alternatively, the following is more comprehensive but extends Nullable<> as well. I didn't know if you wanted to go that far... |
|
Thanks for the contribution! Did you consider the Select extension method? It seems like it does exactly what you need (transforms a I see now that the naming I've chosen is probably confusing. Do you think both Regarding extensions for structs - I like the idea! |
|
I did completely miss that 😞 I was looking for something similar to OnSuccess() for Result<>. I think Select is the logical choice, I'll work with that for now. |
|
Still great suggestion regarding structs! I'll add it soon and will roll out a new version of the lib. |
|
As overloads to Select? I'm happy to amend the PR if that helps? |
Yes.
Would be very helpful, thanks! |
|
So I've run into a blocker here. The methods and have the same signature. Despite the different type constraints. More info here https://blogs.msdn.microsoft.com/ericlippert/2009/12/10/constraints-are-not-part-of-the-signature/ The solution to this isn't immediately apparent to me 😕 (My original code had |
|
Ah, indeed, return values also don't count as overloads. |
| action(maybe.Value); | ||
| } | ||
|
|
||
| public static TOut Execute<T, TOut>(this Maybe<T> maybe, Func<T, TOut> func) |
There was a problem hiding this comment.
Looks like Map method, not like Execute or Select
There was a problem hiding this comment.
Select == Map in C#. Found some conflicts merging this PR. Could you re-submit?
|
@laurence79 Is this PR still active? Please, fix the merge conflicts or say something :) |
Great library, love the approach and your Enterprise Craftsmanship series 😊
When using the library in my own project I found that I sometimes wanted to return a value from the Maybe<>.Execute() extension method, so I've added a Func<> overload in this PR in the hope that it might be of use to others.