Skip to content

Commit

Permalink
Fix: add missing method for async on builder
Browse files Browse the repository at this point in the history
  • Loading branch information
JohSand committed Sep 19, 2023
1 parent a4ff0fb commit c34c007
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Orsak/EffectBuilder.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3356,6 +3356,13 @@ module Medium =
) : EffectCode<'Env, 'TOverall, 'TResult2, 'Err> =
this.Bind(ValueTask<_>(task = t), continuation)

member inline this.Bind<'Env, 'T, 'TOverall, 'TResult1, 'TResult2, 'Err>
(
a: Async<'TResult1>,
continuation: 'TResult1 -> EffectCode<'Env, 'TOverall, 'TResult2, 'Err>
) : EffectCode<'Env, 'TOverall, 'TResult2, 'Err> =
this.Bind(Async.StartAsTask a, continuation)

member inline _.Bind(result: Result<'T, 'Err>, [<InlineIfLambda>] f: 'T -> EffectCode<_, 'TOverall, 'T2, _>) =
EffectCode<'Env, 'TOverall, 'T2, 'Err>(fun sm ->
match result with
Expand All @@ -3367,6 +3374,10 @@ module Medium =
member inline this.ReturnFrom(task: Effect<'Env, 'T, 'Err>) : EffectCode<'Env, 'T, 'T, 'Err> =
this.Bind(task, (fun (t: 'T) -> this.Return t))


member inline this.ReturnFrom(a: Async<'T>) : EffectCode<'Env, 'T, 'T, 'Err> =
this.Bind(Async.StartAsTask a, (fun (t: 'T) -> this.Return t))

member inline this.ReturnFrom(result: Result<'T, 'Err>) : EffectCode<'Env, 'T, 'T, 'Err> =
EffectCode<'Env, 'T, _, 'Err>(fun sm ->
sm.Data.Result <- result
Expand Down
9 changes: 9 additions & 0 deletions tests/Orsak.Tests/Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ module BuilderTests =
return runme =! false
}


[<Fact>]
let ``Can bind async in eff CE`` () =
eff {
let! myValue = async { return 1 }
return myValue
}
|> run

[<Fact>]
let ``Builder should support for with IEnumerable`` () =
run
Expand Down

0 comments on commit c34c007

Please sign in to comment.