I've been writing up a similar idea, based on adaptations of the C++ functions adjacent_find
, unique
, and unique_copy
. I couldn't figure out a good names for some of these, but right now I got:
- For
std::adjacent_find( ForwardIt first, ForwardIt last, BinaryPredicate p )
Collection.firstAdjacentRange(by:)
BidirectionalCollection.lastAdjacentRange(by:)
- For
std::unique( ForwardIt first, ForwardIt last, BinaryPredicate p )
MutableCollection.partitionAwayAdjacentValues(by:)
-
RangeReplaceableCollection.removeAdjacentValues(by:)
, which also needs MC
- For
std::unique_copy( InputIt first, InputIt last, OutputIt d_first, BinaryPredicate p )
Sequence.filterUnique(storingAs: by:)
LazySequenceProtocol.filterUnique(by:)
where the last one's return type of LazyFilterUniqueSequence
follows Collection
or BidirectionalCollection
if the wrapped sequence does.
Does the distinct(by:)
method grabs all subsequent copies of a value, or only the ones that are contiguous (like C++ and my methods)? The difference doesn't matter if the collection is sorted first, like the implementations of remove
in this thread probably would.