Assorted fixes for collections of state (#25)

* Assorted fixes for collections of state

Fixes #21.

* Update IdentifiedArrayTests.swift

* Update case studies

* Run swift-format on _push_ to master

* Format
This commit is contained in:
Stephen Celis
2020-05-06 11:57:20 -04:00
committed by GitHub
parent d6387332a5
commit 4016008d87
7 changed files with 138 additions and 10 deletions

View File

@@ -92,12 +92,15 @@ where ID: Hashable {
}
}
public subscript(id: ID) -> Element? {
public subscript(id id: ID) -> Element? {
get {
self.dictionary[id]
}
_modify {
yield &self.dictionary[id]
if self.dictionary[id] == nil {
self.ids.removeAll(where: { $0 == id })
}
}
}
@@ -115,6 +118,7 @@ where ID: Hashable {
}
}
@discardableResult
public mutating func remove(at position: Int) -> Element {
let id = self.ids.remove(at: position)
let element = self.dictionary[id]!
@@ -138,7 +142,7 @@ where ID: Hashable {
}
public mutating func remove(atOffsets offsets: IndexSet) {
for offset in offsets {
for offset in offsets.reversed() {
_ = self.remove(at: offset)
}
}