Skip to content

Instantly share code, notes, and snippets.

View dzmitry-antonenka's full-sized avatar

Dzmitry Antonenka dzmitry-antonenka

View GitHub Profile
@dzmitry-antonenka
dzmitry-antonenka / SwiftListTreeDataSourceExtension.swift
Last active September 8, 2021 22:33
SwiftListTreeDataSource delete to return indices
/// Deletes the array of`items`.
/// - Parameter items: The array of items to delete.
public func delete(_ items: [ItemIdentifierType]) -> [Int] {
let deleteItemSet = Set(items)
let filterPredicate: (TreeItem<ItemIdentifierType>) -> Bool = { !deleteItemSet.contains($0.value) }
/// Depth first traversal to get include all related deleted expanded children
let deletedItemsWithRelatedExpandedChildren = Set(
items
.compactMap { lookup($0) }