-
Notifications
You must be signed in to change notification settings - Fork 95
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
Feature Request: Add ElseDo and ElseDoAsync #139
Comments
Some time ago I had the same need and added this feature In PR #117 |
In case like this I suggest using below solution, works against 2.0.1 version: 2.ToErrorOr()
.FailIf(val => val == 2, Error.Unexpected())
.Switch(
val => Console.WriteLine("value is not 2"),
_ => Console.WriteLine("value is 2 :(")); |
Right, but at times you only want to log something on error states. You could use the Else method but that takes a Func (instead of an Action) as its argument making the code a bit ugly in my opinion. 2.ToErrorOr()
.FailIf(val => val == 2, Error.Unexpected())
.Else(errors => {
Console.WriteLine("value is 2 :(");
return errors;
}); compared to the ElseDo implementation. 2.ToErrorOr()
.FailIf(val => val == 2, Error.Unexpected())
.ElseDo(_ => Console.WriteLine("value is 2 :(")); |
@cottozen I fully agree. My remark regards the original example posted by @b564518128 . |
@zbyszekprasak Thanks for the response, my need is exactly what @cottozen has described though. |
@zbyszekprasak Another issue with using |
Would really appreciate to see
ElseDo
andElseDoAsync
get added to the toolkit. The relationship betweenElseDo
andElse
would be similar to that betweenThenDo
andThen
. The best use case forElseDo
would be emitting a log when error happened but still want to carry over the error status.example usecase:
The text was updated successfully, but these errors were encountered: