Skip to content

Commit 5f5b98b

Browse files
authored
FileList should conform to Collection (#6845)
It's a little perverse that I can't even ask if the `FileList` `isEmpty`—currently I'm doing `.contains(where: {_ in true})` and `RandomAccessCollection` conformance is even simpler to achieve than `Sequence` conformance. If you really don't want to expose `RandomAccessCollection` conformance to preserve your ability to change the representation arbitrarily, at *least* make it conform to `Collection`, since it is multi-pass.
1 parent 1cb0a66 commit 5f5b98b

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

Sources/PackagePlugin/PackageModel.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,13 @@ extension FileList: Sequence {
418418
}
419419
}
420420

421+
@available(_PackageDescription, introduced: 5.10)
422+
extension FileList: RandomAccessCollection {
423+
public var startIndex: Int { 0 }
424+
public var endIndex: Int { files.endIndex }
425+
public subscript(i: Int) -> File { files[i] }
426+
}
427+
421428
/// Provides information about a single file in a FileList.
422429
public struct File {
423430
/// The path of the file.

0 commit comments

Comments
 (0)