Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept task or async #2

Merged
merged 1 commit into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/AsyncWriterResult/Library.fs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[<AutoOpen>]
module AsyncWriterResult

open System.Threading.Tasks


module Async =

Expand Down Expand Up @@ -261,6 +263,7 @@ type AsyncWriterResultBuilder() =
member __.Bind(m, f) = AsyncWriterResult.bind f m
member __.Zero() = __.Return()
member __.Source(x: Async<Writer<'w, Result<'a, 'b>>>) = x
member __.Source(x: Task<Writer<'w, Result<'a, 'b>>>) = x |> Async.AwaitTask

let asyncWriterResult = AsyncWriterResultBuilder()

Expand All @@ -270,10 +273,13 @@ module AsyncWriterResultBuilderExtensions =
member __.Source(x: Result<'a, 'b>) = x |> AsyncWriter.retn
member __.Source(x: Writer<'w, 't>) = x |> Writer.map Ok |> Async.retn
member __.Source(x: Async<'t>) = x |> Async.map WriterResult.retn
member __.Source(x: Task<'t>) = x |> Async.AwaitTask |> Async.map WriterResult.retn

[<AutoOpen>]
module AsyncWriterResultBuilderExtensionsHighPriority =
type AsyncWriterResultBuilder with
member __.Source(x: Writer<'w, Result<'a, 'b>>) = x |> Async.retn
member __.Source(x: Async<Result<'a, 'b>>) = x |> Async.map Writer.retn
member __.Source(x: Async<Writer<'w, 't>>) = x |> AsyncWriter.map Result.retn
member __.Source(x: Task<Result<'a, 'b>>) = x |> Async.AwaitTask |> Async.map Writer.retn
member __.Source(x: Task<Writer<'w, 't>>) = x |> Async.AwaitTask |> AsyncWriter.map Result.retn
6 changes: 5 additions & 1 deletion src/AsyncWriterResult/TaskWriterResult.fs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ module TaskWriterResult =
member __.Bind(m, f) = bind f m
member __.Zero() = __.Return()
member __.Source(x: Task<Writer<'w, Result<'a, 'b>>>) = x
member __.Source(x: Async<Writer<'w, Result<'a, 'b>>>) = x |> Async.StartAsTask

let taskWriterResult = TaskWriterResultBuilder()

Expand All @@ -122,10 +123,13 @@ module TaskWriterResult =
member __.Source(x: Result<'a, 'b>) = x |> TaskWriter.retn
member __.Source(x: Writer<'w, 't>) = x |> Writer.map Ok |> Task.retn
member __.Source(x: Task<'t>) = x |> Task.map WriterResult.retn
member __.Source(x: Async<'t>) = x |> Async.StartAsTask |> Task.map WriterResult.retn

[<AutoOpen>]
module TaskWriterResultBuilderExtensionsHighPriority =
type TaskWriterResultBuilder with
member __.Source(x: Writer<'w, Result<'a, 'b>>) = x |> Task.retn
member __.Source(x: Task<Result<'a, 'b>>) = x |> Task.map Writer.retn
member __.Source(x: Task<Writer<'w, 't>>) = x |> TaskWriter.map Result.retn
member __.Source(x: Task<Writer<'w, 't>>) = x |> TaskWriter.map Result.retn
member __.Source(x: Async<Result<'a, 'b>>) = x |> Async.StartAsTask |> Task.map Writer.retn
member __.Source(x: Async<Writer<'w, 't>>) = x |> Async.StartAsTask |> TaskWriter.map Result.retn