If / Then - Statements, How can I achieve this functionally speaking? If value == xx, do this, else, do that #477
-
Hello! I am just trying to figure out what the functional equivalent of a Scenario I am trying to call a method, the method has (2) overloads: void MarkForUpdate(DateTime);
void MarkForUpdate<TKey>(TKey, DateTime)
where TKey : IComparable<TKey>, IEquatable<TKey>; Key is usually a type of var _myDateProvider = DateTime.UtcNow;
if (appUserId.IsNullOrDefault())
{
MarkUpdate(_myDateProvider);
}
else
{
MarkUpdate(appUserId, _myDateProvider);
} I would love to achieve this functionally, i'm just not sure of the API methods to do so. Can anyone provide any suggestions please? Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
There are at least 2 options. Option 1: Result.Success(_myDateProvider)
.TapIf(appUserId.IsNullOrDefault(), MarkUpdate)
.TapIf(appUserId.IsNullOrDefault() is false, dp => MarkUpdate(appUserId.Value, dp)); Option 2: Result.SuccessIf(appUserId.IsNullOrDefault(), "appUserId not set")
.Tap(() => MarkUpdate(_myDateProvider))
.TapError(() => MarkUpdate(appUserId.Value, _myDateProvider)); |
Beta Was this translation helpful? Give feedback.
There are at least 2 options.
Option 1:
Option 2: