Skip to content

Commit d22be6a

Browse files
mluisbrownactions-user
authored andcommitted
Run swift-format
1 parent 6b0a4ce commit d22be6a

File tree

4 files changed

+264
-264
lines changed

4 files changed

+264
-264
lines changed

Sources/ComposableArchitecture/Reducer.swift

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ public struct Reducer<State, Action, Environment> {
405405
.map { toLocalAction.embed((index, $0)) }
406406
}
407407
}
408-
408+
409409
/// A version of `pullback` that transforms a reducer that works on an element into one that works
410410
/// on an identified array of elements.
411411
///
@@ -451,34 +451,34 @@ public struct Reducer<State, Action, Environment> {
451451
guard let (id, localAction) = toLocalAction.extract(from: globalAction) else {
452452
return .none
453453
}
454-
454+
455455
// This does not need to be a fatal error because of the unwrap that follows it.
456456
assert(
457457
globalState[keyPath: toLocalState][id: id] != nil,
458458
"""
459-
"\(debugCaseOutput(localAction))" was received by a "forEach" reducer at id \(id) \
460-
when its state contained no element at this id. This is considered an application logic \
461-
error, and can happen for a few reasons:
459+
"\(debugCaseOutput(localAction))" was received by a "forEach" reducer at id \(id) \
460+
when its state contained no element at this id. This is considered an application logic \
461+
error, and can happen for a few reasons:
462462
463-
* This "forEach" reducer was combined with or run from another reducer that removed the \
464-
element at this id when it handled this action. To fix this make sure that this \
465-
"forEach" reducer is run before any other reducers that can move or remove elements from \
466-
state. This ensures that "forEach" reducers can handle their actions for the element at \
467-
the intended id.
463+
* This "forEach" reducer was combined with or run from another reducer that removed the \
464+
element at this id when it handled this action. To fix this make sure that this \
465+
"forEach" reducer is run before any other reducers that can move or remove elements from \
466+
state. This ensures that "forEach" reducers can handle their actions for the element at \
467+
the intended id.
468468
469-
* An in-flight effect emitted this action while state contained no element at this id. \
470-
To fix this make sure that effects for this "forEach" reducer are canceled whenever \
471-
elements are moved or removed from its state. If your "forEach" reducer returns any \
472-
long-living effects, you should use the identifier-based "forEach", instead.
469+
* An in-flight effect emitted this action while state contained no element at this id. \
470+
To fix this make sure that effects for this "forEach" reducer are canceled whenever \
471+
elements are moved or removed from its state. If your "forEach" reducer returns any \
472+
long-living effects, you should use the identifier-based "forEach", instead.
473473
474-
* This action was sent to the store while its state contained no element at this id. \
475-
To fix this make sure that actions for this reducer can only be sent to a view store when \
476-
its state contains an element at this id. In SwiftUI applications, use `ForEachStore`.
477-
""",
474+
* This action was sent to the store while its state contained no element at this id. \
475+
To fix this make sure that actions for this reducer can only be sent to a view store when \
476+
its state contains an element at this id. In SwiftUI applications, use `ForEachStore`.
477+
""",
478478
file: file,
479479
line: line
480480
)
481-
481+
482482
return
483483
self
484484
.reducer(

Sources/ComposableArchitecture/SwiftUI/Identified.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
public struct Identified<ID, Value>: Identifiable where ID: Hashable {
44
public let id: ID
55
public var value: Value
6-
6+
77
/// Initializes an identified value from a given value and a hashable identifier.
88
///
99
/// - Parameters:
@@ -13,7 +13,7 @@ public struct Identified<ID, Value>: Identifiable where ID: Hashable {
1313
self.id = id
1414
self.value = value
1515
}
16-
16+
1717
/// Initializes an identified value from a given value and a function that can return a hashable
1818
/// identifier from the value.
1919
///
@@ -25,7 +25,7 @@ public struct Identified<ID, Value>: Identifiable where ID: Hashable {
2525
public init(_ value: Value, id: (Value) -> ID) {
2626
self.init(value, id: id(value))
2727
}
28-
28+
2929
// NB: This overload works around a bug in key path function expressions and `\.self`.
3030
/// Initializes an identified value from a given value and a function that can return a hashable
3131
/// identifier from the value.
@@ -38,7 +38,7 @@ public struct Identified<ID, Value>: Identifiable where ID: Hashable {
3838
public init(_ value: Value, id: KeyPath<Value, ID>) {
3939
self.init(value, id: value[keyPath: id])
4040
}
41-
41+
4242
public subscript<LocalValue>(
4343
dynamicMember keyPath: WritableKeyPath<Value, LocalValue>
4444
) -> LocalValue {

Sources/ComposableArchitecture/SwiftUI/IdentifiedArray.swift

Lines changed: 63 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,16 @@ public struct IdentifiedArray<ID, Element>: MutableCollection, RandomAccessColle
4141
where ID: Hashable {
4242
/// A key path to a value that identifies an element.
4343
public let id: KeyPath<Element, ID>
44-
44+
4545
/// A raw array of each element's identifier.
4646
public private(set) var ids: [ID]
47-
47+
4848
/// A raw array of the underlying elements.
4949
public var elements: [Element] { Array(self) }
50-
50+
5151
// TODO: Support multiple elements with the same identifier but different data.
5252
private var dictionary: [ID: Element]
53-
53+
5454
/// Initializes an identified array with a sequence of elements and a key
5555
/// path to an element's identifier.
5656
///
@@ -60,92 +60,92 @@ where ID: Hashable {
6060
public init<S>(_ elements: S, id: KeyPath<Element, ID>)
6161
where S: Sequence, S.Element == Element {
6262
self.id = id
63-
63+
6464
let idsAndElements = elements.map { (id: $0[keyPath: id], element: $0) }
6565
self.ids = idsAndElements.map { $0.id }
6666
self.dictionary = Dictionary(idsAndElements, uniquingKeysWith: { $1 })
6767
}
68-
68+
6969
/// Initializes an empty identified array with a key path to an element's
7070
/// identifier.
7171
///
7272
/// - Parameter id: A key path to a value that identifies an element.
7373
public init(id: KeyPath<Element, ID>) {
7474
self.init([], id: id)
7575
}
76-
76+
7777
public var startIndex: Int { self.ids.startIndex }
7878
public var endIndex: Int { self.ids.endIndex }
79-
79+
8080
public func index(after i: Int) -> Int {
8181
self.ids.index(after: i)
8282
}
83-
83+
8484
public func index(before i: Int) -> Int {
8585
self.ids.index(before: i)
8686
}
87-
87+
8888
public subscript(position: Int) -> Element {
8989
// NB: `_read` crashes Xcode Preview compilation.
9090
get { self.dictionary[self.ids[position]]! }
9191
_modify { yield &self.dictionary[self.ids[position]]! }
9292
}
93-
93+
9494
#if DEBUG
95-
/// Direct access to an element by its identifier.
96-
///
97-
/// - Parameter id: The identifier of element to access. Must be a valid identifier for an
98-
/// element of the array and will _not_ insert elements that are not already in the array, or
99-
/// remove elements when passed `nil`. Use `append` or `insert(_:at:)` to insert elements. Use
100-
/// `remove(id:)` to remove an element by its identifier.
101-
/// - Returns: The element.
102-
public subscript(id id: ID) -> Element? {
103-
get { self.dictionary[id] }
104-
set {
105-
if newValue != nil && self.dictionary[id] == nil {
106-
fatalError(
107-
"""
108-
Can't update element with identifier \(id) because no such element exists in the array.
109-
110-
If you are trying to insert an element into the array, use the "append" or "insert" \
111-
methods.
112-
"""
113-
)
114-
}
115-
if newValue == nil {
116-
fatalError(
117-
"""
118-
Can't update element with identifier \(id) with nil.
119-
120-
If you are trying to remove an element from the array, use the "remove(id:) method."
121-
"""
122-
)
95+
/// Direct access to an element by its identifier.
96+
///
97+
/// - Parameter id: The identifier of element to access. Must be a valid identifier for an
98+
/// element of the array and will _not_ insert elements that are not already in the array, or
99+
/// remove elements when passed `nil`. Use `append` or `insert(_:at:)` to insert elements. Use
100+
/// `remove(id:)` to remove an element by its identifier.
101+
/// - Returns: The element.
102+
public subscript(id id: ID) -> Element? {
103+
get { self.dictionary[id] }
104+
set {
105+
if newValue != nil && self.dictionary[id] == nil {
106+
fatalError(
107+
"""
108+
Can't update element with identifier \(id) because no such element exists in the array.
109+
110+
If you are trying to insert an element into the array, use the "append" or "insert" \
111+
methods.
112+
"""
113+
)
114+
}
115+
if newValue == nil {
116+
fatalError(
117+
"""
118+
Can't update element with identifier \(id) with nil.
119+
120+
If you are trying to remove an element from the array, use the "remove(id:) method."
121+
"""
122+
)
123+
}
124+
self.dictionary[id] = newValue
123125
}
124-
self.dictionary[id] = newValue
125126
}
126-
}
127127
#else
128-
public subscript(id id: ID) -> Element? {
129-
// NB: `_read` crashes Xcode Preview compilation.
130-
get { self.dictionary[id] }
131-
_modify { yield &self.dictionary[id] }
132-
}
128+
public subscript(id id: ID) -> Element? {
129+
// NB: `_read` crashes Xcode Preview compilation.
130+
get { self.dictionary[id] }
131+
_modify { yield &self.dictionary[id] }
132+
}
133133
#endif
134-
134+
135135
public mutating func insert(_ newElement: Element, at i: Int) {
136136
let id = newElement[keyPath: self.id]
137137
self.dictionary[id] = newElement
138138
self.ids.insert(id, at: i)
139139
}
140-
140+
141141
public mutating func insert<C>(
142142
contentsOf newElements: C, at i: Int
143143
) where C: Collection, Element == C.Element {
144144
for newElement in newElements.reversed() {
145145
self.insert(newElement, at: i)
146146
}
147147
}
148-
148+
149149
/// Removes and returns the element with the specified identifier.
150150
///
151151
/// - Parameter id: The identifier of the element to remove.
@@ -158,12 +158,12 @@ where ID: Hashable {
158158
self.ids.removeAll(where: { $0 == id })
159159
return element!
160160
}
161-
161+
162162
@discardableResult
163163
public mutating func remove(at position: Int) -> Element {
164164
self.remove(id: self.ids.remove(at: position))
165165
}
166-
166+
167167
public mutating func removeAll(where shouldBeRemoved: (Element) throws -> Bool) rethrows {
168168
var ids: [ID] = []
169169
for (index, id) in zip(self.ids.indices, self.ids).reversed() {
@@ -176,34 +176,34 @@ where ID: Hashable {
176176
self.dictionary[id] = nil
177177
}
178178
}
179-
179+
180180
public mutating func remove(atOffsets offsets: IndexSet) {
181181
for offset in offsets.reversed() {
182182
_ = self.remove(at: offset)
183183
}
184184
}
185-
185+
186186
#if canImport(SwiftUI)
187-
public mutating func move(fromOffsets source: IndexSet, toOffset destination: Int) {
188-
self.ids.move(fromOffsets: source, toOffset: destination)
189-
}
187+
public mutating func move(fromOffsets source: IndexSet, toOffset destination: Int) {
188+
self.ids.move(fromOffsets: source, toOffset: destination)
189+
}
190190
#endif
191-
191+
192192
public mutating func sort(by areInIncreasingOrder: (Element, Element) throws -> Bool) rethrows {
193193
try self.ids.sort {
194194
try areInIncreasingOrder(self.dictionary[$0]!, self.dictionary[$1]!)
195195
}
196196
}
197-
197+
198198
public mutating func shuffle<T>(using generator: inout T) where T: RandomNumberGenerator {
199199
ids.shuffle(using: &generator)
200200
}
201-
201+
202202
public mutating func shuffle() {
203203
var rng = SystemRandomNumberGenerator()
204204
self.shuffle(using: &rng)
205205
}
206-
206+
207207
public mutating func reverse() {
208208
ids.reverse()
209209
}
@@ -278,17 +278,17 @@ where Element: Identifiable, ID == Element.ID {
278278
public init() {
279279
self.init([], id: \.id)
280280
}
281-
281+
282282
public mutating func replaceSubrange<C, R>(_ subrange: R, with newElements: C)
283283
where C: Collection, R: RangeExpression, Element == C.Element, Index == R.Bound {
284284
let replacingIds = self.ids[subrange]
285285
let newIds = newElements.map { $0.id }
286286
ids.replaceSubrange(subrange, with: newIds)
287-
287+
288288
for element in newElements {
289289
self.dictionary[element.id] = element
290290
}
291-
291+
292292
for id in replacingIds where !self.ids.contains(id) {
293293
self.dictionary[id] = nil
294294
}

0 commit comments

Comments
 (0)