Skip to content

Commit e3f71e8

Browse files
authored
Add support for ValueOption (#521)
1 parent 80616e3 commit e3f71e8

18 files changed

+282
-0
lines changed

FSharpPlus.sln

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "content", "content", "{8E6D
6464
docsrc\content\type-mult.fsx = docsrc\content\type-mult.fsx
6565
docsrc\content\type-nonempty.fsx = docsrc\content\type-nonempty.fsx
6666
docsrc\content\type-optiont.fsx = docsrc\content\type-optiont.fsx
67+
docsrc\content\type-valueoptiont.fsx = docsrc\content\type-valueoptiont.fsx
6768
docsrc\content\type-parallelarray.fsx = docsrc\content\type-parallelarray.fsx
6869
docsrc\content\type-reader.fsx = docsrc\content\type-reader.fsx
6970
docsrc\content\type-readert.fsx = docsrc\content\type-readert.fsx

docsrc/content/abstraction-applicative.fsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ From F#
5858
- ``'T [,,]``
5959
- ``'T [,,,]``
6060
- ``option<'T>``
61+
- ``voption<'T>``
6162
- ``IObservable<'T>``
6263
- ``Lazy<'T>``
6364
- ``Async<'T>``
@@ -82,6 +83,7 @@ From F#+
8283
- [``State<'S,'T * 'S>``](type-state.html)
8384
- [``StateT<'S,'Monad<'T * 'S>>``](type-statet.html)
8485
- [``OptionT<'Monad<option<'T>>``](type-optiont.html)
86+
- [``ValueOptionT<'Monad<voption<'T>>``](type-valueoptiont.html)
8587
- [``SeqT<'Monad<seq<'T>>``](type-seqt.html)
8688
- [``ListT<'Monad<list<'T>>``](type-listt.html)
8789
- [``ResultT<'Monad<Result<'T,'TError>>``](type-resultt.html)

docsrc/content/abstraction-foldable.fsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ From .Net/F#
5959
- ``list<'T>``
6060
- ``'T []``
6161
- ``option<'T>``
62+
- ``voption<'T>``
6263
- ``ResizeArray<'T>``
6364
- ``ReadOnlyCollection<'T>``
6465
- ``IReadOnlyCollection<'T>``

docsrc/content/abstraction-functor.fsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ From F#
4848
- ``'T [,,]``
4949
- ``'T [,,,]``
5050
- ``option<'T>``
51+
- ``voption<'T>``
5152
- ``IObservable<'T>``
5253
- ``Lazy<'T>``
5354
- ``Async<'T>``
@@ -75,6 +76,7 @@ From F#+
7576
- [``State<'S,'T * 'S>``](type-state.html)
7677
- [``StateT<'S,'Monad<'T * 'S>>``](type-statet.html)
7778
- [``OptionT<'Monad<option<'T>>``](type-optiont.html)
79+
- [``ValueOptionT<'Monad<voption<'T>>``](type-valueoptiont.html)
7880
- [``SeqT<'Monad<seq<'T>>``](type-seqt.html)
7981
- [``ListT<'Monad<list<'T>>``](type-listt.html)
8082
- [``ResultT<'Monad<Result<'T,'TError>>``](type-resultt.html)

docsrc/content/abstraction-monad.fsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ From F#
6868
- ``list<'T>``
6969
- ``array<'T>``
7070
- ``option<'T>``
71+
- ``voption<'T>``
7172
- ``Lazy<'T>``
7273
- ``Async<'T>``
7374
- ``Result<'T,'U>``
@@ -90,6 +91,7 @@ From F#+
9091
- [``State<'S,'T * 'S>``](type-state.html)
9192
- [``StateT<'S,'Monad<'T * 'S>>``](type-statet.html)
9293
- [``OptionT<'Monad<option<'T>>``](type-optiont.html)
94+
- [``ValueOptionT<'Monad<voption<'T>>``](type-valueoptiont.html)
9395
- [``SeqT<'Monad<seq<'T>>``](type-seqt.html)
9496
- [``ListT<'Monad<list<'T>>``](type-listt.html)
9597
- [``ResultT<'Monad<Result<'T,'TError>>``](type-resultt.html)

docsrc/content/abstraction-traversable.fsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ From .Net/F#
5656
- ``list<'T>``
5757
- ``array<'T>``
5858
- ``option<'T>``
59+
- ``voption<'T>``
5960
- ``ResizeArray<'T>``
6061
- ``Map<'K, 'T>``
6162
- ``Result<'T, 'Error>``
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
(*** hide ***)
2+
// This block of code is omitted in the generated HTML documentation. Use
3+
// it to define helpers that you do not want to show in the documentation.
4+
#r @"../../src/FSharpPlus/bin/Release/netstandard2.0/FSharpPlus.dll"
5+
(**
6+
TO-DO Add some docs here !
7+
=========================
8+
9+
Examples
10+
--------
11+
*)
12+
13+
(**
14+
```f#
15+
#r @"nuget: FSharpPlus"
16+
```
17+
*)
18+
19+
open FSharpPlus

src/FSharpPlus/Control/Alternative.fs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ type Empty =
2222
static member inline Empty (_output: ^t when ^t: null and ^t: struct , _mthd: Default1) = id
2323

2424
static member Empty ([<Optional>]_output: option<'T> , [<Optional>]_mthd: Empty ) = None : option<'T>
25+
static member Empty ([<Optional>]_output: voption<'T> , [<Optional>]_mthd: Empty ) = ValueNone : voption<'T>
2526
static member Empty ([<Optional>]_output: list<'T> , [<Optional>]_mthd: Empty ) = [ ] : list<'T>
2627
static member Empty ([<Optional>]_output: 'T [] , [<Optional>]_mthd: Empty ) = [||] : 'T []
2728

@@ -44,6 +45,7 @@ type Append =
4445
static member inline ``<|>`` (x: Choice<_,_> , y , [<Optional>]_mthd: Append ) = match x, y with Choice1Of2 _, _ -> x | Choice2Of2 x, Choice2Of2 y -> Choice2Of2 (Plus.Invoke x y) | _, _ -> y
4546
static member inline ``<|>`` (x: Either<_,_> , y , [<Optional>]_mthd: Append ) = match x with Left _ -> y | xs -> xs
4647
static member ``<|>`` (x: 'T option , y , [<Optional>]_mthd: Append ) = match x with None -> y | xs -> xs
48+
static member ``<|>`` (x: 'T voption , y , [<Optional>]_mthd: Append ) = match x with ValueNone -> y | xs -> xs
4749
static member ``<|>`` (x: 'T list , y , [<Optional>]_mthd: Append ) = x @ y
4850
static member ``<|>`` (x: 'T [] , y , [<Optional>]_mthd: Append ) = Array.append x y
4951

@@ -63,6 +65,9 @@ type IsAltLeftZero =
6365
static member inline IsAltLeftZero (_: ref< ^t> when ^t: null and ^t: struct , _mthd: Default1) = ()
6466

6567
static member IsAltLeftZero (t: ref<option<_> > , _mthd: IsAltLeftZero) = Option.isSome t.Value
68+
#if !FABLE_COMPILER
69+
static member IsAltLeftZero (t: ref<voption<_> >, _mthd: IsAltLeftZero) = ValueOption.isSome t.Value
70+
#endif
6671
static member IsAltLeftZero (t: ref<Result<_,_>> , _mthd: IsAltLeftZero) = match t.Value with (Ok _ ) -> true | _ -> false
6772
static member IsAltLeftZero (t: ref<Choice<_,_>> , _mthd: IsAltLeftZero) = match t.Value with (Choice1Of2 _) -> true | _ -> false
6873

src/FSharpPlus/Control/Applicative.fs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type Apply =
3232
#endif
3333
static member ``<*>`` (f: Async<_> , x: Async<'T> , [<Optional>]_output: Async<'U> , [<Optional>]_mthd: Apply) = Async.apply f x : Async<'U>
3434
static member ``<*>`` (f: option<_> , x: option<'T> , [<Optional>]_output: option<'U> , [<Optional>]_mthd: Apply) = Option.apply f x : option<'U>
35+
static member ``<*>`` (f: voption<_> , x: voption<'T> , [<Optional>]_output: voption<'U> , [<Optional>]_mthd: Apply) = ValueOption.apply f x : voption<'U>
3536
static member ``<*>`` (f: Result<_,'E> , x: Result<'T,'E> , [<Optional>]_output: Result<'b,'E> , [<Optional>]_mthd: Apply) = Result.apply f x : Result<'U,'E>
3637
static member ``<*>`` (f: Choice<_,'E> , x: Choice<'T,'E> , [<Optional>]_output: Choice<'b,'E> , [<Optional>]_mthd: Apply) = Choice.apply f x : Choice<'U,'E>
3738
static member inline ``<*>`` (KeyValue(a: 'Key, f), KeyValue(b: 'Key, x: 'T), [<Optional>]_output: KeyValuePair<'Key,'U>, [<Optional>]_mthd: Apply) : KeyValuePair<'Key,'U> = KeyValuePair (Plus.Invoke a b, f x)
@@ -83,6 +84,10 @@ type Lift2 =
8384
#endif
8485
static member Lift2 (f, (x , y ), _mthd: Lift2) = Async.map2 f x y
8586
static member Lift2 (f, (x , y ), _mthd: Lift2) = Option.map2 f x y
87+
88+
#if !FABLE_COMPILER
89+
static member Lift2 (f, (x , y ), _mthd: Lift2) = ValueOption.map2 f x y
90+
#endif
8691
static member Lift2 (f, (x: Result<'T,'Error> , y: Result<'U,'Error> ), _mthd: Lift2) = Result.map2 f x y
8792
static member Lift2 (f, (x: Choice<'T,'Error> , y: Choice<'U,'Error> ), _mthd: Lift2) = Choice.map2 f x y
8893
static member Lift2 (f, (x: Map<'Key,'T> , y : Map<'Key,'U> ), _mthd: Lift2) = Map.mapValues2 f x y
@@ -121,6 +126,10 @@ type Lift3 =
121126
#endif
122127
static member Lift3 (f, (x , y , z ), _mthd: Lift3) = Async.map3 f x y z
123128
static member Lift3 (f, (x , y , z ), _mthd: Lift3) = Option.map3 f x y z
129+
130+
#if !FABLE_COMPILER
131+
static member Lift3 (f, (x , y , z ), _mthd: Lift3) = ValueOption.map3 f x y z
132+
#endif
124133
static member Lift3 (f, (x: Result<'T,'Error> , y: Result<'U,'Error> , z: Result<'V, 'Error> ), _mthd: Lift3) = Result.map3 f x y z
125134
static member Lift3 (f, (x: Choice<'T,'Error> , y: Choice<'U,'Error> , z: Choice<'V, 'Error> ), _mthd: Lift3) = Choice.map3 f x y z
126135
static member Lift3 (f, (x: Map<'Key,'T> , y: Map<'Key,'U> , z: Map<'Key, 'V> ), _mthd: Lift3) = Map.mapValues3 f x y z
@@ -151,6 +160,9 @@ type IsLeftZero =
151160
static member IsLeftZero (t: ref<list<_>> , _mthd: IsLeftZero) = List.isEmpty t.Value
152161
static member IsLeftZero (t: ref<array<_>> , _mthd: IsLeftZero) = Array.isEmpty t.Value
153162
static member IsLeftZero (t: ref<option<_>> , _mthd: IsLeftZero) = Option.isNone t.Value
163+
#if !FABLE_COMPILER
164+
static member IsLeftZero (t: ref<voption<_>> , _mthd: IsLeftZero) = ValueOption.isNone t.Value
165+
#endif
154166
static member IsLeftZero (t: ref<Result<_,_>> , _mthd: IsLeftZero) = match t.Value with Error _ -> true | _ -> false
155167
static member IsLeftZero (t: ref<Choice<_,_>> , _mthd: IsLeftZero) = match t.Value with Choice2Of2 _ -> true | _ -> false
156168

src/FSharpPlus/Control/Functor.fs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type Iterate =
2121
static member Iterate (x: Lazy<'T> , action) = action x.Value : unit
2222
static member Iterate (x: seq<'T> , action) = Seq.iter action x
2323
static member Iterate (x: option<'T> , action) = match x with Some x -> action x | _ -> ()
24+
static member Iterate (x: voption<'T> , action) = match x with ValueSome x -> action x | _ -> ()
2425
static member Iterate (x: list<'T> , action) = List.iter action x
2526
static member Iterate ((_: 'W, a: 'T), action) = action a :unit
2627
static member Iterate (x: 'T [] , action) = Array.iter action x
@@ -67,6 +68,9 @@ type Map =
6768
static member Map ((x: Task<'T> , f: 'T->'U), _mthd: Map) = Task.map f x : Task<'U>
6869
#endif
6970
static member Map ((x: option<_> , f: 'T->'U), _mthd: Map) = Option.map f x
71+
#if !FABLE_COMPILER
72+
static member Map ((x: voption<_> , f: 'T->'U), _mthd: Map) = ValueOption.map f x
73+
#endif
7074
static member Map ((x: list<_> , f: 'T->'U), _mthd: Map) = List.map f x : list<'U>
7175
static member Map ((g: 'R->'T , f: 'T->'U), _mthd: Map) = (>>) g f
7276
static member Map ((g: Func<'R, 'T> , f: 'T->'U), _mthd: Map) = Func<'R, 'U> (g.Invoke >> f)
@@ -145,6 +149,7 @@ type Unzip =
145149
static member Unzip ((source: Task<'T * 'U> , _output: Task<'T> * Task<'U> ) , _mthd: Unzip ) = Map.Invoke fst source, Map.Invoke snd source
146150
#endif
147151
static member Unzip ((source: option<'T * 'U> , _output: option<'T> * option<'U> ) , _mthd: Unzip ) = Option.unzip source
152+
static member Unzip ((source: voption<'T * 'U> , _output: voption<'T> * voption<'U> ) , _mthd: Unzip ) = ValueOption.unzip source
148153

149154
static member Unzip ((source: list<'T * 'U> , _output: list<'T> * list<'U> ) , _mthd: Unzip ) = List.unzip source
150155
static member Unzip ((source: 'R -> ('T * 'U) , _output: ('R -> 'T) * ('R -> 'U) ) , _mthd: Unzip ) = (fun x -> fst (source x)), (fun x -> snd (source x))
@@ -203,6 +208,7 @@ type Zip =
203208
static member Zip ((x: 'T [] , y: 'U [] , _output: ('T*'U) [] ), _mthd: Zip) = Array.zipShortest x y
204209
static member Zip ((x: ResizeArray<'T> , y: ResizeArray<'U> , _output: ResizeArray<'T*'U> ), _mthd: Zip) = ResizeArray.zipShortest x y
205210
static member Zip ((x: option<'T> , y: option<'U> , _output: option<'T*'U> ), _mthd: Zip) = Option.zip x y
211+
static member Zip ((x: voption<'T> , y: voption<'U> , _output: voption<'T*'U> ), _mthd: Zip) = ValueOption.zip x y
206212
static member Zip ((x: Result<'T, 'Error> , y: Result<'U, 'Error> , _output: Result<'T * 'U, 'Error> ), _mthd: Zip) = Result.zip x y
207213
static member Zip ((x: Async<'T> , y: Async<'U> , _output: Async<'T*'U> ), _mthd: Zip) = Async.zip x y
208214
#if !FABLE_COMPILER

0 commit comments

Comments
 (0)