You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to efficiently remove items from a NonEmpty collection, but I'm not sure what the best strategy is. In the following example, I'm using IdentifiedArray.
extensionStandup{mutatingfunc deleteAttendees(atOffsets indicies:IndexSet){varelements= attendees.elements
for index in indicies {
elements.remove(at: index)}
attendees =NonEmpty(elements)??.init(Attendee())}}
Ideally, would want a more generic approach, with perhaps a default value, to guarantee the collection won't be empty.
Is this cool?
extension NonEmpty where Collection == IdentifiedArrayOf<Attendee> {
func excludingItems(atOffsets indicies: IndexSet) -> Self {
var elements = self.elements
for index in indicies {
elements.remove(at: index)
}
return NonEmpty(elements) ?? .init(Attendee())
}
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
The NonEmpty library is great.
I want to efficiently remove items from a NonEmpty collection, but I'm not sure what the best strategy is. In the following example, I'm using IdentifiedArray.
Is this the de-facto approach?
Or this
Ideally, would want a more generic approach, with perhaps a default value, to guarantee the collection won't be empty.
Is this cool?
Beta Was this translation helpful? Give feedback.
All reactions