Is there a need for some syntactic suger? Or am i too blind to find it?
See original GitHub issueHi, thank you for this nice extensions. Currently i using a similar extension, because of inactivity i assume to change to this one. I used your Maybe<T> functionality extensively to keep the nullables away from me. I came from the scala-world, so in this project am missing some syntactic sugar around the Maybe<T>. In scala it is a little part of pattern matching: e.g.
public static TOut ResolveOr<TIn, TOut>(this Maybe<TIn> source, Func<TIn, TOut> resolver,
Func<TOut> alternative) => !source.HasValue ? alternative.Invoke() : resolver.Invoke(source.Value);
to realize something like this (resolve the Maybe<T> to a TOut):
Maybe<T> value =
IEnumerable
.Select(some things)
.Where(some filter)
.TryFirst();
And then:
var result = value.ResolveOr(
resolver => {do a lot of stuff with resolver and give back a value},
() => {when TryFirst will give back nothing, here you can go an alternative way and give back a value}
)
result is then of the result-type of your resolver/alternative method.
Is there a need to put this generic sugar to your extension or exists those things in your extension but i´m too blind to find it (missing reference or else)?
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
Why is Syntactic Sugar sometimes considered a bad thing?
It is difficult to reason about syntactic sugar if the reasoning takes place without reference to a context. There are lots of examples...
Read more >Teaching syntactic sugar
While I agree with this answer that the conditional expression is more than just sugar, I think the following consideration is important in...
Read more >c# - When to use / not use syntactic sugar
Generally this means avoiding syntactic sugar. It might also mean avoiding pattern matching, list comprehensions, and the like, if those are not ...
Read more >Are macros really useful?
Moreover, thinking too much about the syntactic sugar aspect make them blind to others and more important aspects of macros: in particular, the...
Read more >Is syntactic sugar in programming languages bad?
No, syntactic sugar is not inherently bad. It typically provides an alternative way of expressing something, perhaps in a more convenient, compact, intuitive, ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

There’s an implicit conversion that does that. You can just do this and it will automatically wrap the
nullinto aMaybe:We can add an overload for this method that would omit the selector.
OK, for the Values method there is a
Choosemethod in your project. That seems nearly that what i was looking for. But its usage is a little bit more trickier as i need only a filter for the none-types withoud aFunc<T,U>.As an example:
Your method needs a
Func<T, U> selectoras parameter. If you only need the filter you must write too much.My signature filters only the
None-Valuesand return the rest, so it´s easier to read IMHO.Regards, Laszlo