MutableCollection.swift 434 B

123456789101112131415161718
  1. //
  2. // MutableCollection.swift
  3. // LoopKit Example
  4. //
  5. // Created by Michael Pangburn on 4/21/19.
  6. // Copyright © 2019 LoopKit Authors. All rights reserved.
  7. //
  8. extension MutableCollection {
  9. public mutating func mutateEach(_ body: (inout Element) throws -> Void) rethrows {
  10. var index = startIndex
  11. while index != endIndex {
  12. try body(&self[index])
  13. formIndex(after: &index)
  14. }
  15. }
  16. }