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) ); }
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); } ); }
public static EitherAsync <Error, string> GenerateLinkId(PixelId pixelId) => Right <Error, string>($"{pixelId}-1234").ToAsync();
public static OptionAsync <Pixel> GetPixel(PixelId id) => Option <Pixel> .None.ToAsync();
public static Task <Either <Error, string> > GenerateLinkId(PixelId pixelId) => Task.FromResult(Right <Error, string>($"{pixelId}-1234"));
public static Task <Option <Pixel> > GetPixel(PixelId id) => Task.FromResult(Option <Pixel> .None);