コード例 #1
0
        public async Task Flatten_ReturnsATask()
        {
            var pipeline = CreatePipeline.With(() => 5);
            var task     = pipeline.Flatten();

            Assert.Equal(5, await task);
        }
コード例 #2
0
        public async Task Select_ComposesTaskReturningMethod()
        {
            async Task <int> AddFour(int number) => await(number + 4).AsTask();

            var pipeline = CreatePipeline.With(() => 5).Select(AddFour);
            var task     = pipeline.Flatten();

            Assert.Equal(9, await task);
        }
コード例 #3
0
        public async Task SelectMany_ComposesPipeReturningMethod()
        {
            var initialPipeline = CreatePipeline.With(() => 5);

            var resultingPipeline = initialPipeline.SelectMany(five => CreatePipeline.With(() => five + 4));

            var task = resultingPipeline.Flatten();

            Assert.Equal(9, await task);
        }
コード例 #4
0
        public async Task SelectMany_AllowsLinqSyntacticSugarForMonadicComposition()
        {
            var firstPipeline  = CreatePipeline.With(() => 5);
            var secondPipeline = CreatePipeline.With(() => 6);
            var thirdPipeline  = CreatePipeline.With(() => 9);

            var resultingPipeline = from firstValue in firstPipeline
                                    from secondValue in secondPipeline
                                    from thirdValue in thirdPipeline
                                    select firstValue + secondValue + thirdValue;

            var task = resultingPipeline.Flatten();

            Assert.Equal(20, await task);
        }