What @Ben_Cohen said, however I'm keen to see iff we get higher kinded types and some other generic features if those functions might switch to a different representation.
The following syntax is not valid Swift syntax, it's completely hypothetical and borrows a few forms that were floating around here on the forums:
protocol Sequence {
associatedtype Element
func map<Result>(
_ closure: (Self.Element) throws -> Result.Element /* = { $0 } */
) rethrows -> Result where Result ~= Self
func compactMap<Result>(
_ closure: (Self.Element) throws -> Result.Element?
) rethrows -> Result where Result ~= Self
func flatMap<T, Result>(
_ closure: (Self.Element) throws -> T
) rethrows -> Result
where
T : Sequence,
Result ~= Self,
Result.Element == T.Element
}
Result ~= Self differs from Result == Self that is only a Sequence with un-specified constraints such as Element, which allows us to re-assign it in through type inference of the function. The above example also has a commented out part that indicates that for instance map should by default map to Self if no explicit type provided, otherwise it could theoretically map to any other sequence type.