Files
darwin-apk/Sources/apk/Index/ApkIndex.swift

41 lines
869 B
Swift
Raw Normal View History

2024-11-10 17:51:53 +11:00
/*
* darwin-apk © 2024 Gay Pizza Specifications
* SPDX-License-Identifier: Apache-2.0
*/
2024-11-17 02:31:44 +11:00
public struct ApkIndex: Sendable {
public let packages: [ApkIndexPackage]
}
extension ApkIndex {
func first(name: String) -> ApkIndexPackage? {
self.packages.first {
$0.name == name
}
}
}
public extension ApkIndex {
static func merge<S: Sequence>(_ tables: S) -> Self where S.Element == Self {
Self.init(packages: tables.flatMap(\.packages))
}
2024-11-23 18:21:15 +11:00
static func merge(_ tables: Self...) -> Self {
Self.init(packages: tables.flatMap(\.packages))
}
}
extension ApkIndex {
init(raw: ApkRawIndex) throws {
self.packages = try raw.packages.map {
try ApkIndexPackage(raw: $0)
}
}
}
extension ApkIndex: CustomStringConvertible {
public var description: String {
self.packages.map(String.init).joined(separator: "\n")
}
}