public void TestEffectFunctorComposition() { using (StringWriter sw = new StringWriter()) { Console.SetOut(sw); var fzero = LazyFunction.pureFunction(Console.WriteLine); var effect1 = new Effect <int>(fzero) .Map(x => x + 10); var effect = new Effect <int>(fzero) .Map(x => x + 1) .Map(x => x.ToString()); Assert.Equal("", sw.ToString()); var effectComposed = effect.Chain((string data) => effect1.Map(x => $"{x} - {data}")) .Map(x => x.ToUpper()); Assert.Equal("", sw.ToString()); var res = effectComposed.Run(); Assert.Equal("Launch nuclear missiles!\r\nLaunch nuclear missiles!\r\n", sw.ToString()); Assert.Equal("10 - 1", res); } }
public void TestPureLazyFunction() { using (StringWriter sw = new StringWriter()) { Console.SetOut(sw); LazyFunction.pureFunction(Console.WriteLine); Assert.Equal("", sw.ToString()); } }
public void TestEffectFunctor() { using (StringWriter sw = new StringWriter()) { Console.SetOut(sw); var fzero = LazyFunction.pureFunction(Console.WriteLine); var effect = new Effect <int>(fzero) .Map(x => x + 1) .Map(x => x.ToString()); Assert.Equal("", sw.ToString()); var res = effect.Run(); Assert.Equal("Launch nuclear missiles!\r\n", sw.ToString()); Assert.Equal("1", res); } }