public void TwoParamFunctionIsTailComposable() { var testFunction = TypedLambdas.Lambda <int>((p1, p2) => p1 + p2); var expected = testFunction(2, 3); var composedFunction = testFunction.TailApply(3); var actual = composedFunction(2); Assert.AreEqual(expected, actual); }
public void FiveParamFunctionIsTailComposable() { var testFunction = TypedLambdas.Lambda((int p1, int p2, int p3, int p4, int p5) => (p1 + p2) * (p3 + p4) + p5); var expected = testFunction(1, 2, 3, 4, 5); var composedFunction = testFunction.TailApply(5); var actual = composedFunction(1, 2, 3, 4); Assert.AreEqual(expected, actual); }
public void FourParamFunctionIsComposableWithThreeParams() { var testFunction = TypedLambdas.Lambda((int p1, int p2, int p3, int p4) => (p1 + p2) * (p3 + p4)); var expected = testFunction(1, 2, 3, 4); var completelyComposedFunction = testFunction.Apply(1, 2, 3); var actual = completelyComposedFunction(4); Assert.AreEqual(expected, actual); }
public void ThreeParamFunctionIsTailComposable() { var testFunction = TypedLambdas.Lambda((int p1, int p2, int p3) => (p1 + p2) * p3); var expected = testFunction(2, 3, 4); var composedFunction = testFunction.TailApply(4); var actual = composedFunction(2, 3); Assert.AreEqual(expected, actual); }
public void SevenParamFunctionIsTailComposable() { var testFunction = TypedLambdas.Lambda((int p1, int p2, int p3, int p4, int p5, int p6, int p7) => (p1 + p2) * (p3 + p4) * (p5 + p6) * p7); var expected = testFunction(1, 2, 3, 4, 5, 6, 7); var composedFunction = testFunction.TailApply(7); var actual = composedFunction(1, 2, 3, 4, 5, 6); Assert.AreEqual(expected, actual); }
public void ThreeParamFunctionIsComposableWithOneParam() { var testFunction = TypedLambdas.Lambda((int p1, int p2, int p3) => (p1 + p2) * p3); var expected = testFunction(1, 2, 3); var partiallyComposedFunction = testFunction.Apply(1); var completelyComposedFunction = partiallyComposedFunction.Apply(2); var actual = completelyComposedFunction(3); Assert.AreEqual(expected, actual); }
public void SixParamFunctionIsComposableWithFiveParams() { var testFunction = TypedLambdas.Lambda((int p1, int p2, int p3, int p4, int p5, int p6) => (p1 + p2) * (p3 + p4) * (p5 + p6)); var expected = testFunction(1, 2, 3, 4, 5, 6); var completelyComposedFunction = testFunction.Apply(1, 2, 3, 4, 5); var actual = completelyComposedFunction(6); Assert.AreEqual(expected, actual); }
public void TenParamFunctionIsTailComposable() { var testFunction = TypedLambdas.Lambda((int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8, int p9, int p10) => (p1 + p2) * (p3 + p4) * (p5 + p6) * (p7 + p8) * (p9 + p10)); var expected = testFunction(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); var composedFunction = testFunction.TailApply(10); var actual = composedFunction(1, 2, 3, 4, 5, 6, 7, 8, 9); Assert.AreEqual(expected, actual); }
public void FiveParamFunctionIsComposableWithTwoParams() { var testFunction = TypedLambdas.Lambda((int p1, int p2, int p3, int p4, int p5) => (p1 + p2) * (p3 + p4) + p5); var expected = testFunction(1, 2, 3, 4, 5); var partiallyComposedFunction1 = testFunction.Apply(1, 2); var partiallyComposedFunction2 = partiallyComposedFunction1.Apply(3); var completelyComposedFunction = partiallyComposedFunction2.Apply(4); var actual = completelyComposedFunction(5); Assert.AreEqual(expected, actual); }
public void SixParamFunctionIsComposableWithOneParam() { var testFunction = TypedLambdas.Lambda((int p1, int p2, int p3, int p4, int p5, int p6) => (p1 + p2) * (p3 + p4) * (p5 + p6)); var expected = testFunction(1, 2, 3, 4, 5, 6); var partiallyComposedFunction1 = testFunction.Apply(1); var partiallyComposedFunction2 = partiallyComposedFunction1.Apply(2); var partiallyComposedFunction3 = partiallyComposedFunction2.Apply(3); var partiallyComposedFunction4 = partiallyComposedFunction3.Apply(4); var completelyComposedFunction = partiallyComposedFunction4.Apply(5); var actual = completelyComposedFunction(6); Assert.AreEqual(expected, actual); }
public static Option <int> GetNumberFromUser(Action askMethod, Action reAskMethod, Func <string> getValueMethod, int minValue, int maxValue, int numberOfAttempts) { var askAgain = TypedLambdas.Func <Action, Action, Func <string>, int, int, int, Option <int> >(GetNumberFromUser) .Apply(reAskMethod, reAskMethod, getValueMethod, minValue, maxValue); askMethod(); return(getValueMethod() .TryParseInt() .Match <Option <int> >() .Some().Where(i => i >= minValue && i <= maxValue).Do(Option <int> .Some) .Else(_ => numberOfAttempts.Match().To <Option <int> >() .Where(i => i <= 1).Do(Option <int> .None()) .Else(__ => askAgain(--numberOfAttempts)) .Result()) .Result()); }