Esempio n. 1
0
        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"));
        }
Esempio n. 2
0
        public void TaskMapTrivial()
        {
            var t1 = TaskMonad.Return(5);
            var t2 = t1.Map(Convert.ToString);

            Assert.That(t2.Result, Is.EqualTo("5"));
        }
Esempio n. 3
0
        public void TaskSelectManyMethodChain()
        {
            var m = TaskMonad.Return(5).SelectMany(t1 =>
                                                   TaskMonad.Return(t1 * 10));

            Assert.That(m.Result, Is.EqualTo(50));
        }
Esempio n. 4
0
        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"));
        }
Esempio n. 5
0
        public void TaskSelectLinq()
        {
            var m =
                from t in TaskMonad.Return(5)
                select Convert.ToString(t);

            Assert.That(m.Result, Is.EqualTo("5"));
        }
Esempio n. 6
0
        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"));
        }
Esempio n. 7
0
        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"));
        }
Esempio n. 8
0
        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));
        }
Esempio n. 9
0
        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"));
        }
Esempio n. 10
0
        public void TaskSelectMethodChain()
        {
            var m = TaskMonad.Return(5).Select(Convert.ToString);

            Assert.That(m.Result, Is.EqualTo("5"));
        }
Esempio n. 11
0
        public void Return()
        {
            var m = TaskMonad.Return(5);

            Assert.That(m.Result, Is.EqualTo(5));
        }