public static void Test() { ListM listM = new ListM(); ListHKT <int> pureHKT = (ListHKT <int>)listM.Pure(42, 10007); List <int> pure = pureHKT.value; foreach (var ele in pure) { Console.Write(ele + " "); } // 42 10007 Console.WriteLine(); List <int> list = new List <int>() { 1, 2, 3, 4 }; ListHKT <int> listHKT = new ListHKT <int>(list); ListHKT <double> flatMappedListHKT = (ListHKT <double>)listM.FlatMap(listHKT, v => listM.Pure(v + 0.5, v + 1.5)); List <double> flatMappedList = flatMappedListHKT.value; foreach (var ele in flatMappedList) { Console.Write(ele + " "); } // 1.5 2.5 2.5 3.5 3.5 4.5 4.5 5.5 Console.WriteLine(); }
public void Inital() { listNode.Clear(); ListK.Clear(); ListM.Clear(); listFun.Clear(); dicKtuple.Clear(); dicTotal.Clear(); dicMarkov.Clear(); dicMarkovHao.Clear(); }
public void Either_Monad() { Assert .AreEqual( "30", new EitherX(new Number(27)) .Bind(n => new EitherX(new Number(n.Value + 3))) .Match( l => l.Message, r => r.Value.ToString() ) ); Assert .AreEqual( "30", new EitherX(new Number(27)) .Fmap(a => new Number(a.Value + 3)) .Match( l => l.Message, r => r.Value.ToString() ) ); Assert .AreEqual( "30", new ApplicativeA( a => new Number(a.Value + 3) ) .Apply( new EitherX( new Number(27) ) ) .Match( l => l.Message, r => r.Value.ToString() ) ); var g = new ListM <Number>( new Number(27), new Number(3) ).Fmap(n => n.Value.ToString()); }