private static ITry <ShoppingListWithItems, AddFoodstuffsError> Process(ApiResult <AddFoodstuffsToShoppingListResponse> response) =>
 response.Match(
     s => Try.Success <ShoppingListWithItems, AddFoodstuffsError>(ToShoppingList(s)),
     e => Try.Error <ShoppingListWithItems, AddFoodstuffsError>(e.Message.Match(
                                                                    "Item already added.", _ => AddFoodstuffsError.FoodstuffAlreadyAdded
                                                                    )),
     noConn => throw new NotImplementedException()
Example #2
0
 /// <summary>
 /// Turns the option into a try using the exception in case of empty option.
 /// </summary>
 public static ITry <A, E> ToTry <A, E>(this IOption <A> option, Func <Unit, E> e)
 {
     return(option.Match(
                val => Try.Success <A, E>(val),
                _ => Try.Error <A, E>(e(Unit.Value))
                ));
 }
Example #3
0
 /// <summary>
 /// Maps the error result to a new try.
 /// </summary>
 public static ITry <B, F> FlatMapError <A, E, B, F>(this ITry <A, E> t, Func <E, ITry <B, F> > f)
     where A : B
     where E : F
 {
     return(t.Match(
                s => Try.Success <B, F>(s),
                e => f(e)
                ));
 }
Example #4
0
 private static ITry <Unit, SignUpError[]> Success() =>
 Try.Success <Unit, SignUpError[]>(Unit.Value);
Example #5
0
 private static ITry <IAccount, SignInError> Success(IAccount a) =>
 Try.Success <IAccount, SignInError>(a);
 public static ITry <T, E> ToTry <T, E>(this bool b, Func <Unit, T> ifTrue, Func <Unit, E> ifFalse)
 {
     return(b ? Try.Success <T, E>(ifTrue(Unit.Value)) : Try.Error <T, E>(ifFalse(Unit.Value)));
 }