Skip to content

Commit 70350cf

Browse files
committed
+ Result.bimap
1 parent cf2274f commit 70350cf

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/FSharpPlus/Extensions/Result.fs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@ module Result =
6161
| Error e, _, _
6262
| _, Error e, _
6363
| _, _, Error e -> Error e
64+
65+
/// <summary>Maps both Ok and Error of a Result.</summary>
66+
/// <param name="errorMapper">Function to be applied to source, if it contains an Error value.</param>
67+
/// <param name="okMapper">Function to be applied to source, if it contains an Ok value.</param>
68+
/// <param name="source">The source value, containing an Ok or an Error.</param>
69+
/// <returns>The result of applying the corresponding mapping function.</returns>
70+
let bimap (errorMapper: 'TError -> 'UError) (okMapper: 'T -> 'U) source =
71+
match source with
72+
| Error e -> Error (errorMapper e)
73+
| Ok a -> Ok (okMapper a)
6474

6575
/// <summary>Flattens two nested Results.</summary>
6676
/// <param name="source">The nested Results.</param>

0 commit comments

Comments
 (0)