From fab8e207658725148034926a7aa1578c93c168ae Mon Sep 17 00:00:00 2001 From: Ody Mbegbu Date: Mon, 15 Jul 2024 12:30:11 -0700 Subject: [PATCH] Add Task.ignore (#272) --- gitbook/task/ignore.md | 27 +++++++++++++++++++ .../Task.fs | 4 +++ 2 files changed, 31 insertions(+) create mode 100644 gitbook/task/ignore.md diff --git a/gitbook/task/ignore.md b/gitbook/task/ignore.md new file mode 100644 index 00000000..7655d4c5 --- /dev/null +++ b/gitbook/task/ignore.md @@ -0,0 +1,27 @@ +## Task.ignore + +Namespace: `FsToolkit.ErrorHandling` + +Function Signature: + +```fsharp +Task<'a> -> Task +``` + +This is a shortcut for `Task.map ignore`. + +## Examples + +### Example 1 + +```fsharp +let savePost : CreatePostRequest -> Task +``` + +We can call this with the `do!` syntax inside a computation expression using `Task.ignore` as below: + +```fsharp +let makePost = task { + do! savePost createPostRequest |> Task.ignore +} +``` diff --git a/src/FsToolkit.ErrorHandling.TaskResult/Task.fs b/src/FsToolkit.ErrorHandling.TaskResult/Task.fs index 9fda2cc5..d953fc2f 100644 --- a/src/FsToolkit.ErrorHandling.TaskResult/Task.fs +++ b/src/FsToolkit.ErrorHandling.TaskResult/Task.fs @@ -45,6 +45,10 @@ module Task = let inline map3 ([] f) x y z = apply (map2 f x y) z + /// Allows us to call `do!` syntax inside a computation expression + let inline ignore (x: Task<'a>) = + x + |> map ignore /// Takes two tasks and returns a tuple of the pair let zip (a1: Task<_>) (a2: Task<_>) =