Should there be BidirectionalCollection.dropLast(while:)?

Here's a more elegant one that additionally shows why it's important to expose the bases of the standard library's adapter types:

extension BidirectionalCollection {
    func dropLast(while predicate: (Element) throws -> Bool) rethrows -> Self.SubSequence {
      let head = try self.reversed().drop(while: predicate)
      return self[head.endIndex.base..<head.startIndex.base]
    }
}
1 Like