Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Sources/SectionedQuery/SectionedResults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ where SectionIdentifier: Hashable, Result: PersistentModel {
}
}


internal init(sectionIdentifier: KeyPath<Result, SectionIdentifier>, results: [Result]) {
self.sectionIdentifier = sectionIdentifier

Expand All @@ -70,6 +71,13 @@ where SectionIdentifier: Hashable, Result: PersistentModel {
return Section(id: identifier, elements: elements)
}
}


public func filter(_ isIncluded: (Result) throws -> Bool) rethrows -> Self {
let elements = sections.flatMap { $0.elements }
let filteredElements = try elements.filter(isIncluded)
return .init(sectionIdentifier: sectionIdentifier, results: filteredElements)
}


/// The collection of models that share a specified identifier.
Expand Down