diff --git a/src/FSharpPlus/Control/Functor.fs b/src/FSharpPlus/Control/Functor.fs index 70609fb6b..33857b3e5 100644 --- a/src/FSharpPlus/Control/Functor.fs +++ b/src/FSharpPlus/Control/Functor.fs @@ -45,7 +45,9 @@ type Iterate = static member Iterate (x: Choice<'T, 'E> , action) = match x with Choice1Of2 x -> action x | _ -> () static member Iterate (KeyValue(_: 'Key, x: 'T), action) = action x : unit static member Iterate (x: Map<'Key,'T> , action) = Map.iter (const' action) x + static member Iterate (x: IDictionary<'Key, 'T>, action) = Dict.iterValues action x static member Iterate (x: Dictionary<'Key, 'T> , action) = Dictionary.iterValues action x + static member Iterate (x: IReadOnlyDictionary<'Key, 'T>, action) = IReadOnlyDictionary.iterValues action x static member Iterate (x: _ ResizeArray , action) = ResizeArray.iter action x // Restricted diff --git a/tests/FSharpPlus.Tests/General.fs b/tests/FSharpPlus.Tests/General.fs index 6b393fe27..1f330e1f2 100644 --- a/tests/FSharpPlus.Tests/General.fs +++ b/tests/FSharpPlus.Tests/General.fs @@ -487,6 +487,21 @@ module Functor = let nel = zip (NonEmptyList.ofList [1; 2]) (NonEmptyList.ofList ["a"; "b"; "c"]) CollectionAssert.AreEqual (NonEmptyList.ofList [1,"a"; 2,"b"], nel) + [] + let iterTests () = + let di = new Dictionary() + di.Add (1, 2) + di.Add (3, 4) + let id = dict [1, 2; 3, 4] + let ir = readOnlyDict [1, 2; 3, 4] + + let r = ResizeArray [] + + iter (fun x -> r.Add (string x)) di + iter (fun x -> r.Add (string x)) id + iter (fun x -> r.Add (string x)) ir + CollectionAssert.AreEqual (ResizeArray ["2"; "4"; "2"; "4"; "2"; "4"], r) + module Foldable =