Skip to content

Commit

Permalink
Fix issue with iteration of dictionaries
Browse files Browse the repository at this point in the history
  • Loading branch information
gusty committed Sep 18, 2024
1 parent 2aeab30 commit eef4e98
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/FSharpPlus/Control/Functor.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions tests/FSharpPlus.Tests/General.fs
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,23 @@ module Functor =
let nel = zip (NonEmptyList.ofList [1; 2]) (NonEmptyList.ofList ["a"; "b"; "c"])
CollectionAssert.AreEqual (NonEmptyList.ofList [1,"a"; 2,"b"], nel)

[<Test>]
let iterTests () =
let di = new Dictionary<int, int>()
di.Add (1, 2)
di.Add (3, 4)
let id = dict [1, 2; 3, 4]
let ir = readOnlyDict [1, 2; 3, 4]
let ma = Map.ofList [1, 2; 3, 4]

let r = ResizeArray<string> []

iter (fun x -> r.Add (string x)) di
iter (fun x -> r.Add (string x)) id
iter (fun x -> r.Add (string x)) ir
iter (fun x -> r.Add (string x)) map
CollectionAssert.AreEqual (ResizeArray ["2"; "4"; "2"; "4"; "2"; "4"; "2"; "4"], r)



module Foldable =
Expand Down

0 comments on commit eef4e98

Please sign in to comment.