File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed
src/FsToolkit.ErrorHandling
tests/FsToolkit.ErrorHandling.Tests Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -119,3 +119,12 @@ module Option =
119119 binder x
120120 |> ofNull
121121 | None -> None
122+
123+ let inline maybe
124+ ( [<InlineIfLambda>] onNone : unit -> 'output )
125+ ( [<InlineIfLambda>] onSome : 'a -> 'output )
126+ ( input : 'a option )
127+ : 'output =
128+ match input with
129+ | Some x -> onSome x
130+ | None -> onNone ()
Original file line number Diff line number Diff line change @@ -111,6 +111,22 @@ let bindNullTests =
111111 Expect.equal ( Option.bindNull someBinder value1) ( None) " "
112112 ]
113113
114+ let maybeTests =
115+ testList " Option.maybe Tests" [
116+ testCase " Some"
117+ <| fun _ ->
118+ let value1 = Some 5
119+ let f () = 42
120+ let add2 = (+) 2
121+ Expect.equal ( Option.maybe f add2 value1) 7 " "
122+ testCase " None"
123+ <| fun _ ->
124+ let value1 = None
125+ let f () = 42
126+ let add2 = (+) 2
127+ Expect.equal ( Option.maybe f add2 value1) 42 " "
128+ ]
129+
114130let allTests =
115131 testList " Option Tests" [
116132 traverseResultTests
@@ -119,4 +135,5 @@ let allTests =
119135 ofResultTests
120136 ofNullTests
121137 bindNullTests
138+ maybeTests
122139 ]
You can’t perform that action at this time.
0 commit comments