public void TestApplicative(string foo, int bar, bool?fooBar, bool expected) { var dto = ValidateString(foo) .Select(FuncExtensions.Curry <string, int, bool, Dto>(Dto.Apply)) .Apply(ValidateInt(bar)) .Apply(ValidateBool(fooBar)); Assert.AreEqual(expected, dto.Match( left: error => false, right: val => true)); }
public void TestTraverseMaybe(int[] testData, bool isSome, int[] expected) { Func <int, bool> greaterThanFour = i => i > 4; var keepGreaterThanFour = FuncExtensions.Curry <Func <int, bool>, int, IMaybe <int> >(KeepIf)(greaterThanFour); var result = testData.Traverse(keepGreaterThanFour); Assert.AreEqual(isSome, !result.IsEmpty); if (isSome) { result.Match( just: actual => Io.Apply(() => Assert.AreEqual(expected, actual)), nothing: () => Io.Apply(() => Assert.Fail("Expected to get a result for input {0} but got nothing instead", testData))).UnsafePerformIo(); } }