diff --git a/docsrc/content/abstraction-applicative.fsx b/docsrc/content/abstraction-applicative.fsx index 07fd9a919..7b776eb28 100644 --- a/docsrc/content/abstraction-applicative.fsx +++ b/docsrc/content/abstraction-applicative.fsx @@ -66,7 +66,7 @@ From F# - ``Choice<'T,'U>`` - ``KeyValuePair<'Key,'T>`` - ``'Monoid * 'T`` - - ``'ValueTuple`` + - ``ValueTuple<'Monoid, 'T>`` - ``Task<'T>`` - ``ValueTask<'T>`` - ``'R->'T`` @@ -107,6 +107,13 @@ Restricted: - ``Set<'T>`` - ``IEnumerator<'T>`` +Only for <*> operation: + - ``Map<'Key, 'T>`` + - ``Dictionary<'Key, 'T>`` + - ``IDictionary<'Key, 'T>`` + - ``IReadOnlyDictionary<'Key, 'T>`` + + [Suggest another](https://github.com/fsprojects/FSharpPlus/issues/new) concrete implementation Examples diff --git a/src/FSharpPlus/Control/Applicative.fs b/src/FSharpPlus/Control/Applicative.fs index b956b2605..6256867ae 100644 --- a/src/FSharpPlus/Control/Applicative.fs +++ b/src/FSharpPlus/Control/Applicative.fs @@ -54,6 +54,23 @@ type Apply = | true, vx -> dct.Add (k, vf vx) | _ -> () dct + + static member ``<*>`` (f: IDictionary<'Key,_>, x: IDictionary<'Key,'T> , []_output: IDictionary<'Key,'U> , []_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 ``<*>`` (f: IReadOnlyDictionary<'Key,_>, x: IReadOnlyDictionary<'Key,'T> , []_output: IReadOnlyDictionary<'Key,'U> , []_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> + #if !FABLE_COMPILER static member ``<*>`` (f: Expr<'T->'U>, x: Expr<'T>, []_output: Expr<'U>, []_mthd: Apply) = Expr.Cast<'U> (Expr.Application (f, x)) #endif