Skip to content

Commit e79d7ee

Browse files
committed
Add <*> for IDictionary and IReadOnlyDictionary
1 parent e4cf64b commit e79d7ee

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

docsrc/content/abstraction-applicative.fsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ From F#
6666
- ``Choice<'T,'U>``
6767
- ``KeyValuePair<'Key,'T>``
6868
- ``'Monoid * 'T``
69-
- ``'ValueTuple<Monoid, 'T>``
69+
- ``ValueTuple<'Monoid, 'T>``
7070
- ``Task<'T>``
7171
- ``ValueTask<'T>``
7272
- ``'R->'T``
@@ -107,6 +107,13 @@ Restricted:
107107
- ``Set<'T>``
108108
- ``IEnumerator<'T>``
109109
110+
Only for <*> operation:
111+
- ``Map<'Key, 'T>``
112+
- ``Dictionary<'Key, 'T>``
113+
- ``IDictionary<'Key, 'T>``
114+
- ``IReadOnlyDictionary<'Key, 'T>``
115+
116+
110117
[Suggest another](https://github.com/fsprojects/FSharpPlus/issues/new) concrete implementation
111118
112119
Examples

src/FSharpPlus/Control/Applicative.fs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,23 @@ type Apply =
5454
| true, vx -> dct.Add (k, vf vx)
5555
| _ -> ()
5656
dct
57+
58+
static member ``<*>`` (f: IDictionary<'Key,_>, x: IDictionary<'Key,'T> , [<Optional>]_output: IDictionary<'Key,'U> , [<Optional>]_mthd: Apply) : IDictionary<'Key,'U> =
59+
let dct = Dictionary ()
60+
for KeyValue(k, vf) in f do
61+
match x.TryGetValue k with
62+
| true, vx -> dct.Add (k, vf vx)
63+
| _ -> ()
64+
dct :> IDictionary<'Key,'U>
65+
66+
static member ``<*>`` (f: IReadOnlyDictionary<'Key,_>, x: IReadOnlyDictionary<'Key,'T> , [<Optional>]_output: IReadOnlyDictionary<'Key,'U> , [<Optional>]_mthd: Apply) : IReadOnlyDictionary<'Key,'U> =
67+
let dct = Dictionary ()
68+
for KeyValue(k, vf) in f do
69+
match x.TryGetValue k with
70+
| true, vx -> dct.Add (k, vf vx)
71+
| _ -> ()
72+
dct :> IReadOnlyDictionary<'Key,'U>
73+
5774
#if !FABLE_COMPILER
5875
static member ``<*>`` (f: Expr<'T->'U>, x: Expr<'T>, [<Optional>]_output: Expr<'U>, [<Optional>]_mthd: Apply) = Expr.Cast<'U> (Expr.Application (f, x))
5976
#endif

0 commit comments

Comments
 (0)