Skip to content

Commit

Permalink
Add <*> for IDictionary and IReadOnlyDictionary
Browse files Browse the repository at this point in the history
  • Loading branch information
gusty committed Feb 21, 2023
1 parent f5339c4 commit 35b259d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
9 changes: 8 additions & 1 deletion docsrc/content/abstraction-applicative.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ From F#
- ``Choice<'T,'U>``
- ``KeyValuePair<'Key,'T>``
- ``'Monoid * 'T``
- ``'ValueTuple<Monoid, 'T>``
- ``ValueTuple<'Monoid, 'T>``
- ``Task<'T>``
- ``ValueTask<'T>``
- ``'R->'T``
Expand Down Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions src/FSharpPlus/Control/Applicative.fs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,23 @@ type Apply =
| true, vx -> dct.Add (k, vf vx)
| _ -> ()
dct

static member ``<*>`` (f: IDictionary<'Key,_>, x: IDictionary<'Key,'T> , [<Optional>]_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 ``<*>`` (f: IReadOnlyDictionary<'Key,_>, x: IReadOnlyDictionary<'Key,'T> , [<Optional>]_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>

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

0 comments on commit 35b259d

Please sign in to comment.