Skip to content

Commit

Permalink
+ Result.iterError
Browse files Browse the repository at this point in the history
  • Loading branch information
gusty authored Jan 27, 2024
1 parent 88fd94c commit 06f8d2b
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/FSharpPlus/Extensions/Result.fs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,19 @@ module Result =
/// <returns>A result of the output type of the binder.</returns>
let inline bindError (binder: 'Error->Result<'T,'Error2>) (source: Result<'T,'Error>) = match source with Ok v -> Ok v | Error e -> binder e

/// <summary><c>iterError f inp</c> executes <c>match inp with Ok _ -> () | Error x -> f x</c>.</summary>
///
/// <param name="action">A function to apply to the error part of the source value.</param>
/// <param name="source">The input result.</param>
///
/// <example id="iter-1">
/// <code lang="fsharp">
/// Ok "Hello world" |> Result.iter (printfn "%s") // does nothing
/// Error "Hello world" |> Result.iter (printfn "%s") // prints "Hello world"
/// </code>
/// </example>
let inline iterError ([<InlineIfLambda>]action: 'Error -> unit) (source: Result<'T, 'Error>) = match source with Ok _ -> () | Error x -> action x

/// <summary>Extracts a value from either side of a Result.</summary>
/// <param name="fOk">Function to be applied to source, if it contains an Ok value.</param>
/// <param name="fError">Function to be applied to source, if it contains an Error value.</param>
Expand Down

0 comments on commit 06f8d2b

Please sign in to comment.