based on the standard library’s swiftinterface file, it looks like the documentation comment for Collection.trimmingPrefix(_:)
was cut-and-pasted from Collection.trimmingPrefix(while:)
, which now lacks documentation entirely.
extension Collection where Self.Element : Equatable {
/// Returns a new collection of the same type by removing initial elements
/// that satisfy the given predicate from the start.
/// - Parameter predicate: A closure that takes an element of the sequence
/// as its argument and returns a Boolean value indicating whether the
/// element should be removed from the collection.
/// - Returns: A collection containing the elements of the collection that are
/// not removed by `predicate`.
@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
public func trimmingPrefix<Prefix>(_ prefix: Prefix) -> Self.SubSequence where Prefix : Sequence, Self.Element == Prefix.Element
}
it appears that the misplaced doccomment was already fixed in main, but the new documentation still isn’t clear about what happens if the prefix matches partially.
extension Collection where Element: Equatable {
/// Returns a new collection of the same type by removing `prefix` from the start
/// of the collection.
/// - Parameter prefix: The collection to remove from this collection.
/// - Returns: A collection containing the elements of the collection that are
/// not removed by `prefix`.
@available(SwiftStdlib 5.7, *)
public func trimmingPrefix<Prefix: Sequence>(
_ prefix: Prefix
) -> SubSequence where Prefix.Element == Element {
_trimmingPrefix(FixedPatternConsumer(pattern: prefix))
}
}
how does Collection.trimmingPrefix(_:)
handle failure? is there a more-efficient way to check that the prefix was fully removed without traversing the string a second time with starts(with:)
?