Example #1
0
        public void FutureMonadSelectWithLet()
        {
            var tf1 = new test_future_notready <int>(1);

            var tf4 = from t1 in tf1
                      let r1 = t1 * 2
                               select r1;

            Assert.AreEqual(2, tf4.Value);
        }
Example #2
0
        public void FutureMonadSelectManyWithLet()
        {
            var tf1 = new test_future_notready <int>(1);
            var tf2 = new test_future_notready <int>(2);

            var tf4 = from t1 in tf1
                      let r1 = t1 * 2
                               from t2 in tf2
                               select r1 + t2;

            Assert.AreEqual(4, tf4.Value);
        }
Example #3
0
        public void SelectForOneAsMonadNotReady()
        {
            var tf1 = new test_future_notready <int>(3);

            var tf2 = from t1 in tf1 select t1 * 2;

            Assert.IsFalse(tf2.HasValue);
            Assert.IsFalse(tf1.HasValue);
            Assert.AreEqual(6, tf2.Value);
            Assert.IsTrue(tf2.HasValue);
            Assert.AreEqual(1, tf1.ValueCalled);
        }
Example #4
0
        public void SelectManyTwoMonadsNotReady()
        {
            var tf1 = new test_future_notready <int>(6);
            var tf2 = new test_future_notready <int>(3);

            var t3 = from t1 in tf1 from t2 in tf2 select t1 / t2;

            Assert.IsFalse(t3.HasValue);
            Assert.IsFalse(tf1.HasValue);
            Assert.IsFalse(tf2.HasValue);
            Assert.AreEqual(2, t3.Value);
            Assert.AreEqual(1, tf1.ValueCalled);
            Assert.AreEqual(1, tf2.ValueCalled);
            Assert.IsTrue(t3.HasValue);
            Assert.AreEqual(1, tf1.ValueCalled);
            Assert.AreEqual(1, tf2.ValueCalled);
        }
Example #5
0
        public void SelectManyThreeMonadsNotReady()
        {
            var tf1 = new test_future_notready <int>(1);
            var tf2 = new test_future_notready <int>(5);
            var tf3 = new test_future_notready <int>(10);

            var tf4 = from t1 in tf1 from t2 in tf2 from t3 in tf3 select t1 + t2 + t3;

            Assert.IsFalse(tf4.HasValue);
            Assert.IsFalse(tf1.HasValue);
            Assert.IsFalse(tf2.HasValue);
            Assert.IsFalse(tf3.HasValue);
            Assert.AreEqual(16, tf4.Value);
            Assert.AreEqual(1, tf1.ValueCalled);
            Assert.AreEqual(1, tf2.ValueCalled);
            Assert.AreEqual(1, tf3.ValueCalled);
            Assert.IsTrue(tf4.HasValue);
            Assert.AreEqual(1, tf1.ValueCalled);
            Assert.AreEqual(1, tf2.ValueCalled);
            Assert.AreEqual(1, tf3.ValueCalled);
        }