public void TaskFlatMapTrivial() { var t1 = Task.FromResult(5); var t2 = t1.FlatMap(n => TaskMonad.Return(Convert.ToString(n))); Assert.That(t2.Result, Is.EqualTo("5")); }
public void TaskMapTrivial() { var t1 = TaskMonad.Return(5); var t2 = t1.Map(Convert.ToString); Assert.That(t2.Result, Is.EqualTo("5")); }
public void TaskSelectManyMethodChain() { var m = TaskMonad.Return(5).SelectMany(t1 => TaskMonad.Return(t1 * 10)); Assert.That(m.Result, Is.EqualTo(50)); }
public void TaskSelectManyOverloadMethodChain() { var m = TaskMonad.Return(5).SelectMany(t1 => TaskMonad.Return(10), (t1, t2) => Convert.ToString(t1 * t2)); Assert.That(m.Result, Is.EqualTo("50")); }
public void TaskSelectLinq() { var m = from t in TaskMonad.Return(5) select Convert.ToString(t); Assert.That(m.Result, Is.EqualTo("5")); }
public void UsingMapToTryToMimicFlatMap() { var t1 = TaskMonad.Return(5); var t2 = t1.Map(n => TaskMonad.Return(Convert.ToString(n))); // t2 is Task<Task<string>> instead of Task<string>. Assert.That(t2.Result.Result, Is.EqualTo("5")); }
public void TaskSelectManyOverloadLinq() { var m = from t1 in TaskMonad.Return(5) from t2 in TaskMonad.Return(10) select Convert.ToString(t1 *t2); Assert.That(m.Result, Is.EqualTo("50")); }
public void TaskSelectManyLinq() { var m = from t1 in TaskMonad.Return(5) from t2 in TaskMonad.Return(t1 * 10) select t2; Assert.That(m.Result, Is.EqualTo(50)); }
public void TaskFlatMapRealistic() { var t1 = Task.Factory.StartNew(() => { MimicRealisticProcessing(); return(5); }); var t2 = t1.FlatMap(n => TaskMonad.Return(Convert.ToString(n))); Assert.That(t2.Result, Is.EqualTo("5")); }
public void TaskSelectMethodChain() { var m = TaskMonad.Return(5).Select(Convert.ToString); Assert.That(m.Result, Is.EqualTo("5")); }
public void Return() { var m = TaskMonad.Return(5); Assert.That(m.Result, Is.EqualTo(5)); }