Skip to content

Commit 966b56d

Browse files
authored
AnyCollection (#68)
1 parent 0cee012 commit 966b56d

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

Sources/SelectableForEach/SelectionState.swift

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ extension SelectionState {
5151
)
5252
}
5353

54-
public static func multiple<C: Collection>(
55-
selected: C,
54+
public static func multiple<Identifier: Hashable>(
55+
selected: some Collection<Identifier>,
5656
canSelectMore: Bool,
57-
onChange: @escaping (_ selected: C.Element, _ selection: SelectAction) -> Void
58-
) -> Self where Self == SelectionStateContainers.Multiple<C>, C.Element: Hashable {
57+
onChange: @escaping (_ selected: Identifier, _ selection: SelectAction) -> Void
58+
) -> Self where Self == SelectionStateContainers.Multiple<Identifier> {
5959
.init(
6060
selected: selected,
6161
canSelectMore: canSelectMore,
@@ -125,38 +125,36 @@ public enum SelectionStateContainers {
125125

126126
}
127127

128-
public struct Multiple<C: Collection>: SelectionState where C.Element: Hashable {
128+
public struct Multiple<Identifier: Hashable>: SelectionState {
129129

130-
public typealias Identifier = C.Element
131-
132-
public let selected: C
130+
public let selected: any Collection<Identifier>
133131

134132
public let canSelectMore: Bool
135133

136-
private let onChange: (_ selected: C.Element, _ action: SelectAction) -> Void
134+
private let onChange: (_ selected: Identifier, _ action: SelectAction) -> Void
137135

138136
public init(
139-
selected: C,
137+
selected: any Collection<Identifier>,
140138
canSelectMore: Bool,
141-
onChange: @escaping (_ selected: C.Element, _ action: SelectAction) -> Void
139+
onChange: @escaping (_ selected: Identifier, _ action: SelectAction) -> Void
142140
) {
143141
self.selected = selected
144142
self.canSelectMore = canSelectMore
145143
self.onChange = onChange
146144
}
147145

148-
public func isSelected(for id: C.Element) -> Bool {
146+
public func isSelected(for id: Identifier) -> Bool {
149147
selected.contains(id)
150148
}
151149

152-
public func isEnabled(for id: C.Element) -> Bool {
150+
public func isEnabled(for id: Identifier) -> Bool {
153151
if isSelected(for: id) {
154152
return true
155153
}
156154
return canSelectMore
157155
}
158156

159-
public func update(isSelected: Bool, for identifier: C.Element) {
157+
public func update(isSelected: Bool, for identifier: Identifier) {
160158
if isSelected {
161159
onChange(identifier, .selected)
162160
} else {

0 commit comments

Comments
 (0)