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 f2e49ba
Show file tree
Hide file tree
Showing 2 changed files with 18 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
16 changes: 16 additions & 0 deletions tests/FSharpPlus.Tests/General.fs
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,22 @@ 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 li = [1, 2; 3, 4]
let di: Dictionary<int, int> = ofList li
let id = dict li
let ir = readOnlyDict li
let ma = Map.ofList li

let r = ResizeArray<string> []

iter (r.Add << string) di
iter (r.Add << string) id
iter (r.Add << string) ir
iter (r.Add << string) ma
CollectionAssert.AreEqual (ResizeArray ["2"; "4"; "2"; "4"; "2"; "4"; "2"; "4"], r)



module Foldable =
Expand Down

0 comments on commit f2e49ba

Please sign in to comment.