Skip to content

Commit e4cf64b

Browse files
committed
IReadOnlyDictionary: deprecate map in favor of mapValues
1 parent 0b0b9f6 commit e4cf64b

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/FSharpPlus/Control/Functor.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ type Map with
129129
static member Map ((x: NonEmptySeq<_> , f: 'T->'U), _mthd: Default2) = NonEmptySeq.map f x : NonEmptySeq<'U>
130130
static member Map ((x: IEnumerator<_> , f: 'T->'U), _mthd: Default2) = Enumerator.map f x : IEnumerator<'U>
131131
static member Map ((x: IDictionary<_,_> , f: 'T->'U), _mthd: Default2) = Dict.map f x : IDictionary<'Key,'U>
132-
static member Map ((x: IReadOnlyDictionary<_,_>, f: 'T->'U), _mthd: Default2) = IReadOnlyDictionary.map f x : IReadOnlyDictionary<'Key,_>
132+
static member Map ((x: IReadOnlyDictionary<_,_>, f: 'T->'U), _mthd: Default2) = IReadOnlyDictionary.mapValues f x : IReadOnlyDictionary<'Key,_>
133133
static member Map ((x: IObservable<'T> , f: 'T->'U), _mthd: Default2) = Observable.map f x : IObservable<'U>
134134
#if !FABLE_COMPILER
135135
static member Map ((x: Nullable<_> , f: 'T->'U), _mthd: Default2) = Nullable.map f x : Nullable<'U>

src/FSharpPlus/Extensions/IReadOnlyDictionary.fs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,19 @@ module IReadOnlyDictionary =
5050
let values (source: IReadOnlyDictionary<'Key, 'Value>) = Seq.map (fun (KeyValue(_, v)) -> v) source
5151

5252
/// <summary>Maps the given function over each value in the read-only dictionary.</summary>
53-
/// <param name="f">The mapping function.</param>
54-
/// <param name="x">The input IReadOnlyDictionary.</param>
53+
/// <param name="mapper">The mapping function.</param>
54+
/// <param name="source">The input IReadOnlyDictionary.</param>
5555
///
5656
/// <returns>The mapped IReadOnlyDictionary.</returns>
57-
let map f (x: IReadOnlyDictionary<'Key, 'T>) =
57+
let mapValues mapper (source: IReadOnlyDictionary<'Key, 'T>) =
5858
let dct = Dictionary<'Key, 'U> ()
59-
for KeyValue(k, v) in x do
60-
dct.Add (k, f v)
59+
for KeyValue(k, v) in source do
60+
dct.Add (k, mapper v)
6161
dct :> IReadOnlyDictionary<'Key, 'U>
6262

63+
[<System.Obsolete("Name is a bit ambiguous, use mapValues if the intention is to map only over the values or mapi to map over both keys and values.")>]
64+
let map f (x: IReadOnlyDictionary<'Key, 'T>) = mapValues f x // F#+ 2: if following F# core naming, it should point to mapi instead.
65+
6366
/// <summary>Creates a read-only dictionary value from a pair of read-only dictionaries,
6467
/// using a function to combine them.</summary>
6568
/// <remarks>Keys that are not present on both read-only dictionaries are dropped.</remarks>

0 commit comments

Comments
 (0)