Skip to content

Commit 5cb444c

Browse files
committed
Add missing iter functions to Extensions
1 parent 941e4b4 commit 5cb444c

File tree

7 files changed

+53
-9
lines changed

7 files changed

+53
-9
lines changed

src/FSharpPlus/Extensions/Dict.fs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@ module Dict =
4646
/// <returns>A seq of the values in the dictionary.</returns>
4747
let values (source: IDictionary<_, _>) = Seq.map (fun (KeyValue(_, v)) -> v) source
4848

49+
/// <summary>Applies the given function to each key and value pair of the dictionary.</summary>
50+
/// <param name="action">The function to apply to each key and value pair of the input dictionary.</param>
51+
/// <param name="source">The input dictionary.</param>
52+
let iter action (source: IDictionary<'Key, 'T>) = for KeyValue(k, v) in source do action k v
53+
54+
/// <summary>Applies the given function to each value of the dictionary.</summary>
55+
/// <param name="action">The function to apply to each value of the input dictionary.</param>
56+
/// <param name="source">The input dictionary.</param>
57+
let iterValues action (source: IDictionary<'Key, 'T>) = for KeyValue(_, v) in source do action v
58+
4959
/// <summary>Maps the given function over each value in the dictionary.</summary>
5060
/// <param name="mapper">The mapping function.</param>
5161
/// <param name="source">The input dictionary.</param>

src/FSharpPlus/Extensions/Dictionary.fs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@ module Dictionary =
4848
/// <returns>A seq of the values in the dictionary.</returns>
4949
let values (source: Dictionary<_,_>) = Seq.map (fun (KeyValue(_, v)) -> v) source
5050

51+
/// <summary>Applies the given function to each key and value pair of the dictionary.</summary>
52+
/// <param name="action">The function to apply to each key and value pair of the input dictionary.</param>
53+
/// <param name="source">The input dictionary.</param>
54+
let iter action (source: Dictionary<'Key, 'T>) = for KeyValue(k, v) in source do action k v
55+
56+
/// <summary>Applies the given function to each value of the dictionary.</summary>
57+
/// <param name="action">The function to apply to each value of the input dictionary.</param>
58+
/// <param name="source">The input dictionary.</param>
59+
let iterValues action (source: Dictionary<'Key, 'T>) = for KeyValue(_, v) in source do action v
60+
5161
/// <summary>Maps the given function over each value in the dictionary.</summary>
5262
/// <param name="mapping">The mapping function.</param>
5363
/// <param name="source">The input dictionary.</param>

src/FSharpPlus/Extensions/IReadOnlyCollection.fs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,10 @@ module IReadOnlyCollection =
1111
let ofList (source: 'T list) = source :> IReadOnlyCollection<'T>
1212
let ofSeq (source: seq<'T>) = source |> Array.ofSeq :> IReadOnlyCollection<'T>
1313
let map mapping (source: IReadOnlyCollection<'T>) = Seq.map mapping source |> Seq.toArray :> IReadOnlyCollection<'U>
14-
let iter mapping (source: IReadOnlyCollection<'T>) = Seq.iter mapping source
14+
15+
/// <summary>Applies the given function to each element of the collection.</summary>
16+
/// <param name="action">The function to apply to elements from the input collection.</param>
17+
/// <param name="source">The input collection.</param>
18+
let iter action (source: IReadOnlyCollection<'T>) = Seq.iter action source
19+
1520
let isEmpty (source: IReadOnlyCollection<'T>) = source.Count = 0

src/FSharpPlus/Extensions/IReadOnlyDictionary.fs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@ module IReadOnlyDictionary =
4949
/// <returns>A seq of the values in the read-only dictionary.</returns>
5050
let values (source: IReadOnlyDictionary<'Key, 'Value>) = Seq.map (fun (KeyValue(_, v)) -> v) source
5151

52+
/// <summary>Applies the given function to each key and value pair of the read-only dictionary.</summary>
53+
/// <param name="action">The function to apply to each key and value pair of the input dictionary.</param>
54+
/// <param name="source">The input dictionary.</param>
55+
let iter action (source: IReadOnlyDictionary<'Key, 'T>) = for KeyValue(k, v) in source do action k v
56+
57+
/// <summary>Applies the given function to each value of the read-only dictionary.</summary>
58+
/// <param name="action">The function to apply to each value of the input dictionary.</param>
59+
/// <param name="source">The input dictionary.</param>
60+
let iterValues action (source: IReadOnlyDictionary<'Key, 'T>) = for KeyValue(_, v) in source do action v
61+
5262
/// <summary>Maps the given function over each value in the read-only dictionary.</summary>
5363
/// <param name="mapper">The mapping function.</param>
5464
/// <param name="source">The input IReadOnlyDictionary.</param>
@@ -106,13 +116,6 @@ module IReadOnlyDictionary =
106116
dct.Add (k, mapper k v)
107117
dct :> IReadOnlyDictionary<'Key, 'U>
108118

109-
/// <summary>Applies the given action over each key and value in the read-only dictionary.</summary>
110-
/// <param name="action">The action to apply.</param>
111-
/// <param name="source">The input IReadOnlyDictionary.</param>
112-
///
113-
/// <returns>The mapped IReadOnlyDictionary.</returns>
114-
let iter action (source: IReadOnlyDictionary<'Key, 'T>) = for KeyValue(k, v) in source do action k v
115-
116119

117120
/// <summary>Applies a function to each value in a read-only dictionary and then returns
118121
/// a read-only dictionary of entries <c>v</c> where the applied function returned <c>Some(v)</c>.

src/FSharpPlus/Extensions/IReadOnlyList.fs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,7 @@ module IReadOnlyList =
3232
if 0 <= i && i < source.Count then Some source.[i]
3333
else None
3434

35-
let iter mapping (source: IReadOnlyList<'T>) = Seq.iter mapping source
35+
/// <summary>Applies the given function to each element of the collection.</summary>
36+
/// <param name="action">The function to apply to elements from the input list.</param>
37+
/// <param name="source">The input list.</param>
38+
let iter action (source: IReadOnlyList<'T>) = Seq.iter action source

src/FSharpPlus/Extensions/Map.fs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ module Map =
3333
/// </remarks>
3434
let values (source: Map<'Key, 'T>) = Seq.map (fun (KeyValue(_, v)) -> v) source
3535

36+
/// <summary>Applies the given function to each value of the Map.</summary>
37+
/// <param name="action">The function to apply to each value of the input Map.</param>
38+
/// <param name="source">The input Map.</param>
39+
let iterValues action (source: Map<'Key, 'T>) = Map.iter (fun _ v -> action v) source
40+
3641
/// <summary>Maps the values of the original Map.</summary>
3742
/// <remarks>
3843
/// The core `Map.map` function maps over values too, but it passes both

src/FSharpPlus/Extensions/ResizeArray.fs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ module ResizeArray =
2121

2222
ResizeArray (Seq.map mapping source)
2323

24+
/// <summary>Applies the given function to each element of the collection.</summary>
25+
/// <param name="action">The function to apply to elements from the input ResizeArray.</param>
26+
/// <param name="source">The input ResizeArray.</param>
27+
let iter (action: 'T -> 'U) (source: ResizeArray<'T>) =
28+
raiseIfNull (nameof source) source
29+
30+
ResizeArray (Seq.map action source)
31+
2432
/// <summary>Applies a ResizeArray of functions to a ResizeArray of values and concatenates them.</summary>
2533
/// <param name="f">The functions.</param>
2634
/// <param name="ra">The values.</param>

0 commit comments

Comments
 (0)