# Idea: mutatingForEach for Collections

**URL:** <https://forums.swift.org/t/idea-mutatingforeach-for-collections/18442>\
**Category:** Discussion\
**Created:** [November 30, 2018, 3:36pm UTC](https://forums.swift.org/t/idea-mutatingforeach-for-collections/18442 "2018-11-30T15:36:45Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![nnnnnnnn](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/nnnnnnnn/32/264_2.png) [@nnnnnnnn](https://forums.swift.org/u/nnnnnnnn)\
**Post date:** [November 30, 2018, 4:39pm UTC](https://forums.swift.org/t/idea-mutatingforeach-for-collections/18442/5 "2018-11-30T16:39:38Z")

</div>

This sounds like a useful addition! Note that `Dictionary` is troublesome as always — this method would need to be added in an extension to `MutableCollection`, but dictionaries themselves aren't mutable collections, only their `Values` sub-collections are. If you're okay with modifying the values independent of the keys, that's great, but if not, to solve your use case we might additionally need a `modifyEachValueWithKey` (I can come up with terrible names all day). That would look something like this:

```swift
extension Dictionary {
    mutating func modifyEachValueWithKey(
        _ body: (Key, inout Value) throws -> Void
    ) rethrows
}

```

---

_[View the full topic](https://forums.swift.org/t/idea-mutatingforeach-for-collections/18442)._
