I’m going through the list of common sequence APIs that I’ve had to implement multiple times in several projects and I’d like to pitch a couple of APIs on sequence, modulo naming.
/// Presents a sequence of the elements in `firstSequence` followed by those in `secondSequence`. firstSequence.followed(by: secondSequence)
/// An infinite sequence of containing the elements of `sequence` repeated forever. sequence.repeated(.forever) /// An sequence containing the elements of `sequence` repeated twice. sequence.repeated(.times(2))
/// The elements of `sequence` batched by subsequences of `count == 2`, except for remainder elements, which an have a `count < 2`. sequence.batched(maxBatchSize: 2)
You’ve probably seen some of these in Python’s
itertools. These are the ones that I find come up the most often.
I have implementations for these that I can share if you’d like to try it out but they’re pretty simple to implement; I’m sure a lot of you have implemented them yourselves.