Skip to content

Commit 06f8d2b

Browse files
authored
+ Result.iterError
1 parent 88fd94c commit 06f8d2b

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/FSharpPlus/Extensions/Result.fs

+13
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,19 @@ module Result =
8888
/// <returns>A result of the output type of the binder.</returns>
8989
let inline bindError (binder: 'Error->Result<'T,'Error2>) (source: Result<'T,'Error>) = match source with Ok v -> Ok v | Error e -> binder e
9090

91+
/// <summary><c>iterError f inp</c> executes <c>match inp with Ok _ -> () | Error x -> f x</c>.</summary>
92+
///
93+
/// <param name="action">A function to apply to the error part of the source value.</param>
94+
/// <param name="source">The input result.</param>
95+
///
96+
/// <example id="iter-1">
97+
/// <code lang="fsharp">
98+
/// Ok "Hello world" |> Result.iter (printfn "%s") // does nothing
99+
/// Error "Hello world" |> Result.iter (printfn "%s") // prints "Hello world"
100+
/// </code>
101+
/// </example>
102+
let inline iterError ([<InlineIfLambda>]action: 'Error -> unit) (source: Result<'T, 'Error>) = match source with Ok _ -> () | Error x -> action x
103+
91104
/// <summary>Extracts a value from either side of a Result.</summary>
92105
/// <param name="fOk">Function to be applied to source, if it contains an Ok value.</param>
93106
/// <param name="fError">Function to be applied to source, if it contains an Error value.</param>

0 commit comments

Comments
 (0)