From 16affd2b41bd4324fc4a8e00b3f97968f6cf8983 Mon Sep 17 00:00:00 2001 From: Blair55 Date: Sun, 22 Nov 2020 10:28:40 +0000 Subject: [PATCH] Add awr apply function and operators module --- src/AsyncWriterResult/Library.fs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/AsyncWriterResult/Library.fs b/src/AsyncWriterResult/Library.fs index f088615..d85d083 100644 --- a/src/AsyncWriterResult/Library.fs +++ b/src/AsyncWriterResult/Library.fs @@ -157,6 +157,24 @@ module AsyncWriterResult = | Error e -> return Writer <| fun () -> Error e, logs1 } + let apply f m = + async { + let! uf = f + let! um = m + let (r1, logs1) = Writer.run uf + let (r2, logs2) = Writer.run um + match r1, r2 with + | Ok g, Ok h -> return Writer <| fun () -> Ok(g h), logs1 @ logs2 + | Error e1, _ -> return Writer <| fun () -> Error e1, logs1 @ logs2 + | _, Error e2 -> return Writer <| fun () -> Error e2, logs1 @ logs2 + } + + module Operators = + + let () = map + let (>>=) = bind + let (<*>) = apply + let write log = async { return Writer(fun () -> Result.retn (), [ log ]) } @@ -234,4 +252,4 @@ type AsyncWriterResultBuilder() = member __.Bind(m, f) = AsyncWriterResult.bind f m member __.Zero() = __.Return() -let asyncWriterResult = AsyncWriterResultBuilder() +let asyncWriterResult = AsyncWriterResultBuilder() \ No newline at end of file