Skip to content

Commit

Permalink
+ Applicative and Functor overloads
Browse files Browse the repository at this point in the history
  • Loading branch information
gusty committed Nov 28, 2022
1 parent ffcf317 commit 7b50816
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/FSharpPlus/Control/Applicative.fs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type Apply =
static member ``<*>`` (f: _ [] , x: 'T [] , [<Optional>]_output: 'U [] , [<Optional>]_mthd: Apply) = Array.apply f x : 'U []
static member ``<*>`` (f: 'r -> _ , g: _ -> 'T , [<Optional>]_output: 'r -> 'U , [<Optional>]_mthd: Apply) = fun x -> let f' = f x in f' (g x) : 'U
static member inline ``<*>`` ((a: 'Monoid, f) , (b: 'Monoid, x: 'T) , [<Optional>]_output: 'Monoid * 'U , [<Optional>]_mthd: Apply) = (Plus.Invoke a b, f x) : 'Monoid *'U
static member inline ``<*>`` (struct (a: 'Monoid, f), struct (b: 'Monoid, x: 'T), [<Optional>]_output: struct ('Monoid * 'U), [<Optional>]_mthd: Apply) = struct (Plus.Invoke a b, f x) : struct ('Monoid * 'U)
#if !FABLE_COMPILER
static member ``<*>`` (f: Task<_> , x: Task<'T> , [<Optional>]_output: Task<'U> , [<Optional>]_mthd: Apply) = Task.apply f x : Task<'U>
#endif
Expand Down Expand Up @@ -78,6 +79,7 @@ type Lift2 =
static member Lift2 (f, (x , y ), _mthd: Lift2) = Array.lift2 f x y
static member Lift2 (f, (x: 'R -> 'T , y: 'R -> 'U ), _mthd: Lift2) = fun a -> f (x a) (y a)
static member inline Lift2 (f, ((a: 'Monoid, x: 'T) , (b: 'Monoid, y: 'U) ), _mthd: Lift2) = Plus.Invoke a b, f x y
static member inline Lift2 (f, (struct (a: 'Monoid, x: 'T), struct (b: 'Monoid, y: 'U)), _mthd: Lift2) = struct (Plus.Invoke a b, f x y)
#if !FABLE_COMPILER
static member Lift2 (f, (x: Task<'T> , y: Task<'U> ), _mthd: Lift2) = Task.map2 f x y
#endif
Expand Down
4 changes: 4 additions & 0 deletions src/FSharpPlus/Control/Functor.fs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ type Map =
static member Map ((g: 'R->'T , f: 'T->'U), _mthd: Map) = (>>) g f
static member Map ((g: Func<'R, 'T> , f: 'T->'U), _mthd: Map) = Func<'R, 'U> (g.Invoke >> f)
static member Map (((m: 'Monoid, a) , f: 'T->'U), _mthd: Map) = (m, f a)
static member Map ((struct (m: 'Monoid, a) , f: 'T->'U), _mthd: Map) = struct (m, f a)
static member Map ((x: _ [] , f: 'T->'U), _mthd: Map) = Array.map f x
#if !FABLE_COMPILER
static member Map ((x: _ [,] , f: 'T->'U), _mthd: Map) = Array2D.map f x
Expand Down Expand Up @@ -150,6 +151,7 @@ type Unzip =
static member Unzip ((source: 'R -> ('T * 'U) , _output: ('R -> 'T) * ('R -> 'U) ) , _mthd: Unzip ) = (fun x -> fst (source x)), (fun x -> snd (source x))
static member Unzip ((source: Func<'R, ('T * 'U)> , _output: Func<'R,'T> * Func<'R,'U> ) , _mthd: Unzip ) = Func<_,_> (fun x -> fst (source.Invoke x)), Func<_,_> (fun x -> snd (source.Invoke x))
static member Unzip (((m: 'Monoid, t: ('T * 'U)) , _output: ('Monoid * 'T) * ('Monoid * 'U) ) , _mthd: Unzip ) = (m, fst t), (m, snd t)
static member Unzip ((struct (m: 'Monoid, t: ('T * 'U)) , _output: struct ('Monoid * 'T) * struct ('Monoid * 'U) ) , _mthd: Unzip ) = struct (m, fst t), struct (m, snd t)
static member Unzip ((source: ('T * 'U) [] , _output: 'T [] * 'U [] ) , _mthd: Unzip ) = Array.unzip source
#if !FABLE_COMPILER
static member Unzip ((source: ('T * 'U) [,] , _output: 'T [,] * 'U [,] ) , _mthd: Unzip ) = Map.Invoke fst source, Map.Invoke snd source
Expand Down Expand Up @@ -230,6 +232,7 @@ type Bimap =
inherit Default1

static member Bimap ((x: 'T1, y: 'T2) , f: 'T1->'U1, g: 'T2->'U2, [<Optional>]_mthd: Bimap) = (f x, g y)
static member Bimap (struct (x: 'T1, y: 'T2), f: 'T1->'U1, g: 'T2->'U2, [<Optional>]_mthd: Bimap) = struct (f x, g y)
static member Bimap (x: Result<'T2, 'T1> , f: 'T1->'U1, g: 'T2->'U2, [<Optional>]_mthd: Bimap) = Result.either (Ok << g) (Error << f) x
static member Bimap (KeyValue(k:'T1, x:'T2), f: 'T1->'U1, g: 'T2->'U2, [<Optional>]_mthd: Bimap) = KeyValuePair (f k, g x)
static member Bimap (x: Choice<'T2, 'T1> , f: 'T1->'U1, g: 'T2->'U2, [<Optional>]_mthd: Bimap) = Choice.either (Choice1Of2 << g) (Choice2Of2 << f) x
Expand All @@ -248,6 +251,7 @@ type MapFirst =
inherit Default1

static member First ((x: 'T1, y: 'T2) , f: 'T1->'U1, [<Optional>]_mthd: MapFirst) = (f x, y)
static member First (struct (x: 'T1, y: 'T2) , f: 'T1->'U1, [<Optional>]_mthd: MapFirst) = struct (f x, y)
static member First (x: Result<'T2, 'T1> , f: 'T1->'U1, [<Optional>]_mthd: MapFirst) = Result.either Ok (Error << f) x
static member First (x: Choice<'T2, 'T1> , f: 'T1->'U1, [<Optional>]_mthd: MapFirst) = Choice.either Choice1Of2 (Choice2Of2 << f) x
static member First (KeyValue(k: 'T1, x: 'T2), f: 'T1->'U1, [<Optional>]_mthd: MapFirst) = KeyValuePair (f k, x)
Expand Down

0 comments on commit 7b50816

Please sign in to comment.