Skip to content
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
37 changes: 6 additions & 31 deletions src/FSharpPlus/Control/Applicative.fs
Original file line number Diff line number Diff line change
Expand Up @@ -42,40 +42,15 @@ type Apply =
let f, x = f.Value, x.Value
KeyValuePair2 (Plus.Invoke a b, f x)

static member ``<*>`` (struct (f: Map<'Key,_> , x: Map<'Key,'T> ) , _output: Map<'Key,'U> , [<Optional>]_mthd: Apply) : Map<'Key,'U> = Map (seq {
for KeyValue(k, vf) in f do
match Map.tryFind k x with
| Some vx -> yield k, vf vx
| _ -> () })

static member ``<*>`` (struct (f: Dictionary<'Key,_>, x: Dictionary<'Key,'T>) , _output: Dictionary<'Key,'U> , [<Optional>]_mthd: Apply) : Dictionary<'Key,'U> =
let dct = Dictionary ()
for KeyValue(k, vf) in f do
match x.TryGetValue k with
| true, vx -> dct.Add (k, vf vx)
| _ -> ()
dct

static member ``<*>`` (struct (f: IDictionary<'Key,_>, x: IDictionary<'Key,'T>) , _output: IDictionary<'Key,'U> , [<Optional>]_mthd: Apply) : IDictionary<'Key,'U> =
let dct = Dictionary ()
for KeyValue(k, vf) in f do
match x.TryGetValue k with
| true, vx -> dct.Add (k, vf vx)
| _ -> ()
dct :> IDictionary<'Key,'U>

static member ``<*>`` (struct (f: IReadOnlyDictionary<'Key,_>, x: IReadOnlyDictionary<'Key,'T>) , _output: IReadOnlyDictionary<'Key,'U> , [<Optional>]_mthd: Apply) : IReadOnlyDictionary<'Key,'U> =
let dct = Dictionary ()
for KeyValue(k, vf) in f do
match x.TryGetValue k with
| true, vx -> dct.Add (k, vf vx)
| _ -> ()
dct :> IReadOnlyDictionary<'Key,'U>
static member ``<*>`` (struct (f: Map<'Key,_> , x: Map<'Key,'T> ) , _output: Map<'Key,'U> , [<Optional>]_mthd: Apply) : Map<'Key,'U> = Map.apply f x
static member ``<*>`` (struct (f: Dictionary<'Key,_> , x: Dictionary<'Key,'T> ) , _output: Dictionary<'Key,'U> , [<Optional>]_mthd: Apply) : Dictionary<'Key,'U> = Dictionary.apply f x
static member ``<*>`` (struct (f: IDictionary<'Key,_> , x: IDictionary<'Key,'T> ) , _output: IDictionary<'Key,'U> , [<Optional>]_mthd: Apply) : IDictionary<'Key,'U> = Dict.apply f x
static member ``<*>`` (struct (f: IReadOnlyDictionary<'Key,_>, x: IReadOnlyDictionary<'Key,'T>) , _output: IReadOnlyDictionary<'Key,'U>, [<Optional>]_mthd: Apply) : IReadOnlyDictionary<'Key,'U> = IReadOnlyDictionary.apply f x

#if !FABLE_COMPILER
static member ``<*>`` (struct (f: Expr<'T->'U>, x: Expr<'T>), _output: Expr<'U>, [<Optional>]_mthd: Apply) = Expr.Cast<'U> (Expr.Application (f, x))
static member ``<*>`` (struct (f: Expr<'T->'U>, x: Expr<'T>), _output: Expr<'U>, [<Optional>]_mthd: Apply) = Expr.Cast<'U> (Expr.Application (f, x))
#endif
static member ``<*>`` (struct (f: ('T->'U) ResizeArray, x: 'T ResizeArray), _output: 'U ResizeArray, [<Optional>]_mthd: Apply) = ResizeArray.apply f x : 'U ResizeArray
static member ``<*>`` (struct (f: ('T->'U) ResizeArray, x: 'T ResizeArray), _output: 'U ResizeArray, [<Optional>]_mthd: Apply) = ResizeArray.apply f x : 'U ResizeArray

static member inline Invoke (f: '``Applicative<'T -> 'U>``) (x: '``Applicative<'T>``) : '``Applicative<'U>`` =
let inline call (mthd : ^M, input1: ^I1, input2: ^I2, output: ^R) =
Expand Down
7 changes: 7 additions & 0 deletions src/FSharpPlus/Control/Foldable.fs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ type FoldMap =
static member inline FoldMap (x: Set<_> , f, [<Optional>]_impl: FoldMap) = Seq.fold (fun x y -> Plus.Invoke x (f y)) (Zero.Invoke ()) x
static member inline FoldMap (x: _ [] , f, [<Optional>]_impl: FoldMap) = Array.fold (fun x y -> Plus.Invoke x (f y)) (Zero.Invoke ()) x

static member inline FoldMap (x: Map<_, _> , f, [<Optional>]_impl: FoldMap) = Map.fold (fun x _ y -> Plus.Invoke x (f y)) (Zero.Invoke ()) x
static member inline FoldMap (x: IDictionary<_, _> , f, [<Optional>]_impl: FoldMap) = Dict.fold (fun x _ y -> Plus.Invoke x (f y)) (Zero.Invoke ()) x
static member inline FoldMap (x: IReadOnlyDictionary<_, _>, f, [<Optional>]_impl: FoldMap) = IReadOnlyDictionary.fold (fun x _ y -> Plus.Invoke x (f y)) (Zero.Invoke ()) x

static member inline Invoke (f: 'T->'Monoid) (x: '``Foldable'<T>``) : 'Monoid =
let inline call_2 (a: ^a, b: ^b, f) = ((^a or ^b) : (static member FoldMap : _*_*_ -> _) b, f, a)
let inline call (a: 'a, b: 'b, f) = call_2 (a, b, f)
Expand Down Expand Up @@ -185,6 +189,9 @@ type Fold =
static member Fold (x: list<_> , f, z , [<Optional>]_impl: Fold ) = List.fold f z x
static member Fold (x: Set<_> , f, z , [<Optional>]_impl: Fold ) = Set.fold f z x
static member Fold (x: _ [] , f, z , [<Optional>]_impl: Fold ) = Array.fold f z x
static member Fold (x: Map<_,_> , f, z , [<Optional>]_impl: Fold ) = Map.fold (fun s _ -> f s) z x
static member Fold (x: IDictionary<_,_> , f, z , [<Optional>]_impl: Fold ) = Dict.fold (fun s _ -> f s) z x
static member Fold (x: IReadOnlyDictionary<_,_>, f, z , [<Optional>]_impl: Fold ) = IReadOnlyDictionary.fold (fun s _ -> f s) z x

static member inline Invoke (folder: 'State->'T->'State) (state: 'State) (foldable: '``Foldable'<T>``) : 'State =
let inline call_2 (a: ^a, b: ^b, f, z) = ((^a or ^b) : (static member Fold : _*_*_*_ -> _) b, f, z, a)
Expand Down
26 changes: 13 additions & 13 deletions src/FSharpPlus/Control/Functor.fs
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,13 @@ type Unzip =
static member inline Unzip ((source: '``Functor<'T * 'U>`` , _output: '``Functor<'T>`` * '``Functor<'U>`` ) , _mthd: Default1) = (^``Functor<'T * 'U>``: (static member Unzip : _->_) source) : '``Functor<'T>`` * '``Functor<'U>``
static member inline Unzip (( _ : ^t when ^t: null and ^t: struct , _ ) , _ ) = ()

static member Unzip ((source: Lazy<'T * 'U> , _output: Lazy<'T> * Lazy<'U> ) , _mthd: Unzip ) = Map.Invoke fst source, Map.Invoke snd source
static member Unzip ((source: Lazy<'T * 'U> , _output: Lazy<'T> * Lazy<'U> ) , _mthd: Unzip ) = Lazy.map fst source, Lazy.map snd source

#if !FABLE_COMPILER
static member Unzip ((source: Task<'T * 'U> , _output: Task<'T> * Task<'U> ) , _mthd: Unzip ) = Map.Invoke fst source, Map.Invoke snd source
static member Unzip ((source: Task<'T * 'U> , _output: Task<'T> * Task<'U> ) , _mthd: Unzip ) = Task.map fst source, Task.map snd source
#endif
#if !FABLE_COMPILER
static member Unzip ((source: ValueTask<'T * 'U> , _output: ValueTask<'T> * ValueTask<'U> ) , _mthd: Unzip ) = Map.Invoke fst source, Map.Invoke snd source
static member Unzip ((source: ValueTask<'T * 'U> , _output: ValueTask<'T> * ValueTask<'U> ) , _mthd: Unzip ) = ValueTask.map fst source, ValueTask.map snd source
#endif
static member Unzip ((source: option<'T * 'U> , _output: option<'T> * option<'U> ) , _mthd: Unzip ) = Option.unzip source
static member Unzip ((source: voption<'T * 'U> , _output: voption<'T> * voption<'U> ) , _mthd: Unzip ) = ValueOption.unzip source
Expand All @@ -167,17 +167,17 @@ type Unzip =
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
static member Unzip ((source: ('T * 'U) [,,] , _output: 'T [,,] * 'U [,,] ) , _mthd: Unzip ) = Map.Invoke fst source, Map.Invoke snd source
static member Unzip ((source: ('T * 'U) [,,,] , _output: 'T [,,,] * 'U [,,,] ) , _mthd: Unzip ) = Map.Invoke fst source, Map.Invoke snd source
static member Unzip ((source: ('T * 'U) [,] , _output: 'T [,] * 'U [,] ) , _mthd: Unzip ) = Array2D.map fst source, Array2D.map snd source
static member Unzip ((source: ('T * 'U) [,,] , _output: 'T [,,] * 'U [,,] ) , _mthd: Unzip ) = Array3D.map fst source, Array3D.map snd source
static member Unzip ((source: ('T * 'U) [,,,] , _output: 'T [,,,] * 'U [,,,] ) , _mthd: Unzip ) = Map.Invoke fst source, Map.Invoke snd source
#endif

static member Unzip ((source: Async<'T * 'U> , _output: Async<'T> * Async<'U> ) , _mthd: Unzip ) = Map.Invoke fst source, Map.Invoke snd source
static member Unzip ((source: Async<'T * 'U> , _output: Async<'T> * Async<'U> ) , _mthd: Unzip ) = Async.map fst source, Async.map snd source
static member Unzip ((source: Result<'T * 'U, 'E> , _output: Result<'T,'E> * Result<'U,'E> ) , _mthd: Unzip ) = Result.unzip source
static member Unzip ((source: Choice<'T * 'U, 'E> , _output: Choice<'T,'E> * Choice<'U,'E> ) , _mthd: Unzip ) = Map.Invoke fst source, Map.Invoke snd source
static member Unzip ((source: Choice<'T * 'U, 'E> , _output: Choice<'T,'E> * Choice<'U,'E> ) , _mthd: Unzip ) = Choice.map fst source, Choice.map snd source
static member Unzip ((source: KeyValuePair<'Key, 'T * 'U> , _output: KeyValuePair<_, 'T> * KeyValuePair<_, 'U> ) , _mthd: Unzip ) = Map.Invoke fst source, Map.Invoke snd source
static member Unzip ((source: Map<'Key, 'T * 'U> , _output: Map<_, 'T> * Map<_, 'U> ) , _mthd: Unzip ) = Map.unzip source
static member Unzip ((source: Dictionary<'Key, 'T * 'U> , _output: Dictionary<_, 'T> * Dictionary<_, 'U> ) , _mthd: Unzip ) = Map.Invoke fst source, Map.Invoke snd source
static member Unzip ((source: Map<'Key, 'T * 'U> , _output: Map<_, 'T> * Map<_, 'U> ) , _mthd: Unzip ) = Map.unzip source
static member Unzip ((source: Dictionary<'Key, 'T * 'U> , _output: Dictionary<_, 'T> * Dictionary<_, 'U> ) , _mthd: Unzip ) = Dictionary.unzip source

#if !FABLE_COMPILER
static member Unzip ((source: Expr<'T * 'U> , _output: Expr<'T> * Expr<'U> ) , _mthd: Unzip ) = Map.Invoke fst source, Map.Invoke snd source
Expand All @@ -187,10 +187,10 @@ type Unzip =

static member Unzip ((source: seq<'T * 'U> , _output: seq<'T> * seq<'U> ) , _mthd: Unzip ) = Map.Invoke fst source, Map.Invoke snd source

static member Unzip ((source: IEnumerator<'T * 'U> , _output: IEnumerator<'T> * ResizeArray<'U> ) , _mthd: Unzip ) = Map.Invoke fst source, Map.Invoke snd source
static member Unzip ((source: IEnumerator<'T * 'U> , _output: IEnumerator<'T> * ResizeArray<'U> ) , _mthd: Unzip ) = Enumerator.map fst source, Enumerator.map snd source
static member Unzip ((source: IDictionary<'Key, 'T * 'U> , _output: IDictionary<_,'T> * IDictionary<_,'U> ) , _mthd: Unzip ) = Dict.unzip source
static member Unzip ((source: IReadOnlyDictionary<'Key,'T * 'U> , _output: IReadOnlyDictionary<_,'T> * IReadOnlyDictionary<_,'U>) , _mthd: Unzip ) = IReadOnlyDictionary.unzip source
static member Unzip ((source: IObservable<'T * 'U> , _output: IObservable<'T> * ResizeArray<'U> ) , _mthd: Unzip ) = Map.Invoke fst source, Map.Invoke snd source
static member Unzip ((source: IObservable<'T * 'U> , _output: IObservable<'T> * ResizeArray<'U> ) , _mthd: Unzip ) = Observable.map fst source, Observable.map snd source



Expand All @@ -208,7 +208,7 @@ type Zip =
static member Zip ((x: seq<'T> , y: seq<'U> , _output: seq<'T*'U> ), _mthd: Zip) = Seq.zip x y
static member Zip ((x: IDictionary<'K, 'T> , y: IDictionary<'K,'U> , _output: IDictionary<'K,'T*'U> ), _mthd: Zip) = Dict.zip x y
static member Zip ((x: IReadOnlyDictionary<'K, 'T>, y: IReadOnlyDictionary<'K,'U>, _output: IReadOnlyDictionary<'K,'T*'U>), _mthd: Zip) = IReadOnlyDictionary.zip x y
static member Zip ((x: Dictionary<'K, 'T> , y: Dictionary<'K,'U> , _output: Dictionary<'K,'T*'U> ), _mthd: Zip) = Dict.zip x y :?> Dictionary<'K,'T*'U>
static member Zip ((x: Dictionary<'K, 'T> , y: Dictionary<'K,'U> , _output: Dictionary<'K,'T*'U> ), _mthd: Zip) = Dictionary.zip x y
static member Zip ((x: Map<'K, 'T> , y: Map<'K,'U> , _output: Map<'K,'T*'U> ), _mthd: Zip) = Map.zip x y
static member Zip ((f: 'R -> 'T , g: 'R -> 'U , _output: 'R -> 'T * 'U ), _mthd: Zip) = fun x -> (f x, g x)
static member Zip ((f: Func<'R, 'T> , g: Func<'R, 'U> , _output: Func<'R, 'T * 'U> ), _mthd: Zip) = Func<_,_> (fun x -> (f.Invoke x, g.Invoke x))
Expand Down
Loading
Loading