Skip to content

Commit a11cfbc

Browse files
ratsclubTheAngryByrd
authored andcommitted
Added bind operator for Validation
Close #188
1 parent 9a8682a commit a11cfbc

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/FsToolkit.ErrorHandling/ValidationOp.fs

+6-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ open FsToolkit.ErrorHandling
44

55
[<AutoOpen>]
66
module Validation =
7-
87
let inline (<!>)
98
([<InlineIfLambda>] mapper: 'okInput -> 'okOutput)
109
(input: Validation<'okInput, 'error>)
@@ -28,3 +27,9 @@ module Validation =
2827
(input: Result<'okInput, 'error>)
2928
: Validation<'okOutput, 'error> =
3029
Validation.apply applier (Validation.ofResult input)
30+
31+
let inline (>>=)
32+
(input: Validation<'okInput, 'error>)
33+
([<InlineIfLambda>] binder: 'okInput -> Validation<'okOutput, 'error>)
34+
: Validation<'okOutput, 'error> =
35+
Validation.bind binder input

tests/FsToolkit.ErrorHandling.Tests/Validation.fs

+2-2
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,14 @@ let applyTests =
104104
let operatorsTests =
105105

106106
testList "Validation Operators Tests" [
107-
testCase "map & apply operators"
107+
testCase "map, apply & bind operators"
108108
<| fun _ ->
109109
createPostRequest
110110
<!> (lift validLatR)
111111
<*> (lift validLngR)
112112
<*> (lift validTweetR)
113+
>>= (fun tweet -> Ok tweet)
113114
|> Expect.hasOkValue validCreatePostRequest
114-
115115
testCase "map^ & apply^ operators"
116116
<| fun _ ->
117117
createPostRequest

0 commit comments

Comments
 (0)