mirror of
https://github.com/pointfreeco/swift-composable-architecture.git
synced 2025-12-24 12:14:25 +01:00
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:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user