-
.NET Boolean type usually makes Functional Boolean should be more like However, my issues with Either type are the following:
There is a library that solves this, here are some examples TrueOrFalse IsWeekend()
{
var dow = DateTimeOffset.Now.DayOfWeek;
if (dow == DayOfWeek.Saturday || dow == DayOfWeek.Sunday)
{
return new TrueOrFalse.True();
}
return new TrueOrFalse.False();
}
YesNoOrMaybe CanPurchaseAlcohol(int age)
{
if (age < 16)
{
return new YesNoOrMaybe.No();
}
if (age >= 21)
{
return new YesNoOrMaybe.Yes();
}
return new YesNoOrMaybe.Maybe();
} However, I have issues with this one as well
I was thinking to create a specialized type, let's call it Binate (still working on the name) which will be similar to However, that will mean copying and renaming types from language-ext My question is, how have you solved this problem in your projects? Which approach would you recommend? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
I'm no expert, so please feel free to take any other advice that comes along, but I would start that way and see where it got me. |
Beta Was this translation helpful? Give feedback.
-
What is the actual problem to solve? I would be confused using |
Beta Was this translation helpful? Give feedback.
-
It's a very strange request. Monads are for chaining operations: they yield a value when they're able to continue. You could consider this to be like If you just want the chaining behaviour of monads use If you desperately want to reproduct the existing behaviour of I answered a question a few years back on 'functional if' on Stack-Overflow, which maybe is closer to what you need. Note though, the |
Beta Was this translation helpful? Give feedback.
It's a very strange request. Monads are for chaining operations: they yield a value when they're able to continue. You could consider this to be like
true
(buttrue
+ a value). If the monad can yield a value it's a truth, if not it's a falsity (false
and no value). That's OK, but in your example the only value that will ever be yielded isUnit
(or a version of). What's the point in that? It has no value outside of chaining operations together. It will never yield a usable value from within the monad (other thantrue
orfalse
).If you just want the chaining behaviour of monads use
&&
withbool
, it does exactly what you're asking for. It stops onfalse
and continues ontrue
. If all aretrue
…