I'm with Daryle that it's really weird to have the searchy methods restricted to BidirectionalCollection. They don't make sense on basically-unordered collections, sure, but they totally do make sense on linked lists or sequences-made-from-functions. (Well, most of them.)
I'll note that I had a use case recently where I wanted split
to actually preserve the separators in the results. You can do this from the API that's here, but it's, uh, not great:
let splits = bigLongString.split(separatedBy: "### ")
let starts = splits.lazy.map { $0.startIndex }
let splitsWithSuffixesExceptLast = zip(starts, starts.dropFirst()).map {
bigLongString[$0.0..<$0.1]
}
let splitsWithSuffixes =
splitsWithSuffixesExceptLast + [bigLongString[starts.last!...]]
Perhaps the right answer here is an enum:
enum IncludingSeparatorsBehavior {
case omitted
case asPrefix
case asSuffix
}
and then the behavior I want is includingSeparators: .asSuffix
. (Note that the only empty subsequences when including separators will be at the beginning or end of the result.)
Or perhaps the right answer is something like what I wrote above, which doesn't pull its weight in making the implementation more complex.