Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added bind operator for Validation #214

Merged
merged 1 commit into from
Apr 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/FsToolkit.ErrorHandling/ValidationOp.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ open FsToolkit.ErrorHandling

[<AutoOpen>]
module Validation =

let inline (<!>)
([<InlineIfLambda>] mapper: 'okInput -> 'okOutput)
(input: Validation<'okInput, 'error>)
Expand All @@ -28,3 +27,9 @@ module Validation =
(input: Result<'okInput, 'error>)
: Validation<'okOutput, 'error> =
Validation.apply applier (Validation.ofResult input)

let inline (>>=)
(input: Validation<'okInput, 'error>)
([<InlineIfLambda>] binder: 'okInput -> Validation<'okOutput, 'error>)
: Validation<'okOutput, 'error> =
Validation.bind binder input
4 changes: 2 additions & 2 deletions tests/FsToolkit.ErrorHandling.Tests/Validation.fs
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,14 @@ let applyTests =
let operatorsTests =

testList "Validation Operators Tests" [
testCase "map & apply operators"
testCase "map, apply & bind operators"
<| fun _ ->
createPostRequest
<!> (lift validLatR)
<*> (lift validLngR)
<*> (lift validTweetR)
>>= (fun tweet -> Ok tweet)
|> Expect.hasOkValue validCreatePostRequest

testCase "map^ & apply^ operators"
<| fun _ ->
createPostRequest
Expand Down