diff --git a/LanguageExt.Core/Effects/IO/DSL/IOMap.cs b/LanguageExt.Core/Effects/IO/DSL/IOMap.cs index 6758df879..901988d06 100644 --- a/LanguageExt.Core/Effects/IO/DSL/IOMap.cs +++ b/LanguageExt.Core/Effects/IO/DSL/IOMap.cs @@ -16,17 +16,53 @@ abstract record IOMapAsync : IODsl record IOMap(A Value, Func F) : IOMap { public override IODsl Map(Func g) => - new IOMap(Value, x => g(F(x))); + new IOMap(Value, F, g); public override B Invoke(EnvIO envIO) => F(Value); } +record IOMap(A Value, Func F, Func G) : IOMap +{ + public override IODsl Map(Func h) => + new IOMap(Value, F, G, h); + + public override C Invoke(EnvIO envIO) => + G(F(Value)); +} + +record IOMap(A Value, Func F, Func G, Func H) : IOMap +{ + public override IODsl Map(Func f) => + new IOMap(Value, F, G, x => f(H(x))); + + public override D Invoke(EnvIO envIO) => + H(G(F(Value))); +} + record IOMapAsync(Task Value, Func F) : IOMapAsync { public override IODsl Map(Func g) => - new IOMapAsync(Value, x => g(F(x))); + new IOMapAsync(Value, F, g); public override async ValueTask Invoke(EnvIO envIO) => F(await Value); } + +record IOMapAsync(Task Value, Func F, Func G) : IOMapAsync +{ + public override IODsl Map(Func h) => + new IOMapAsync(Value, F, G, h); + + public override async ValueTask Invoke(EnvIO envIO) => + G(F(await Value)); +} + +record IOMapAsync(Task Value, Func F, Func G, Func H) : IOMapAsync +{ + public override IODsl Map(Func f) => + new IOMapAsync(Value, F, G, x => f(H(x))); + + public override async ValueTask Invoke(EnvIO envIO) => + H(G(F(await Value))); +} diff --git a/LanguageExt.Core/Effects/IO/Free/IOBind.cs b/LanguageExt.Core/Effects/IO/Free/IOBind.cs index 0b4ec1b5e..c7bd68c32 100644 --- a/LanguageExt.Core/Effects/IO/Free/IOBind.cs +++ b/LanguageExt.Core/Effects/IO/Free/IOBind.cs @@ -18,10 +18,10 @@ abstract record IOBindAsync : IO record IOBind(A Value, Func> F) : IOBind { public override IO Map(Func f) => - new IOBind(Value, x => F(x).Map(f)); + new IOBind(Value, x => F(x).As().Map(f)); public override IO Bind(Func> f) => - new IOBind(Value, x => F(x).Bind(f)); + new IOBind(Value, x => F(x).As().Bind(f)); public override IO Invoke(EnvIO envIO) => F(Value).As(); @@ -30,10 +30,10 @@ public override IO Invoke(EnvIO envIO) => record IOBindAsync(Task Value, Func> F) : IOBindAsync { public override IO Map(Func f) => - new IOBindAsync(Value, x => F(x).Map(f)); + new IOBindAsync(Value, x => F(x).As().Map(f)); public override IO Bind(Func> f) => - new IOBindAsync(Value, x => F(x).Bind(f)); + new IOBindAsync(Value, x => F(x).As().Bind(f)); public override async ValueTask> Invoke(EnvIO envIO) => F(await Value).As();