Add splitMap function to Swift standard library

Taking your questions in reverse!

  1. For the name, I agree that partitionMap is a better match with the behavior of other algorithms. "split" is in a family (with "chunked" and "windows") of methods that divide a collection into subsequences but otherwise maintain their order, with split dropping the separator element(s). This new method is a partition with an added map step baked in for ergonomic reasons.
  1. The Comparable conformance is there so that Either can be used as an index for the EitherSequence type. Rather than designing a proper Either addition to the Algorithms package (it should also be Hashable, Sendable, etc… should it conform to Error?), we can just add a single-purpose enum for this, named something like PartitionMapResult with a first and second case that will map to the position in the resulting tuple. I think that would be a better strategy for this limited purpose.
  1. A PR would be welcome!
7 Likes