Пример #1
0
        public async Task what_i_desire_EitherAsync()
        {
            EitherAsync <Error, Pixel> GetPixelE(PixelId id) =>
            GetPixel(id).ToEither(Error.New("pixel not found"));

            var program =
                from pixel in GetPixelE(PixelId.New("wkrp"))
                from id in GenerateLinkId(pixel.Value)
                from resource in ScrapeUrl("http://google.com")
                select resource;

            await program.Match(
                Right : r => Assert.True(false, "this should not pass"),
                Left : e => Assert.Equal("pixel not found", e.Value)
                );
        }
Пример #2
0
        public async Task what_im_forced_to_do()
        {
            var program =
                from pixel in GetPixel(PixelId.New("wkrp")).AsTry("pixel not found")
                from id in GenerateLinkId(pixel.Value).AsTry()
                from resource in ScrapeUrl("http://google.com").AsTry()
                select resource;

            (await program.Try()).Match(
                Succ: r =>
            {
                Assert.True(false, "this should not pass");
                return(unit);
            },
                Fail: e =>
            {
                Assert.Equal("pixel not found", e.Message);
                return(unit);
            }
                );
        }
Пример #3
0
 public static EitherAsync <Error, string> GenerateLinkId(PixelId pixelId) =>
 Right <Error, string>($"{pixelId}-1234").ToAsync();
Пример #4
0
 public static OptionAsync <Pixel> GetPixel(PixelId id) =>
 Option <Pixel> .None.ToAsync();
Пример #5
0
 public static Task <Either <Error, string> > GenerateLinkId(PixelId pixelId) =>
 Task.FromResult(Right <Error, string>($"{pixelId}-1234"));
Пример #6
0
 public static Task <Option <Pixel> > GetPixel(PixelId id) =>
 Task.FromResult(Option <Pixel> .None);