[swift-evolution] [Manifesto] Completing Generics
plx
plxswift at icloud.com
Thu Mar 3 08:14:51 CST 2016
# Missing Idea: "Type Predicates”
This is another way of attacking the “where clauses get too long” problem; it may already be implicitly part of “generic typealiases”.
Consider being able to write a declaration like this:
protocol SpecializedContainer {
associatedtype Element: Comparable
// potential declaration:
typepredicate Compatible(S:SequenceType) = S.Generator.Element == Element
// potential use syntaxes (tbd):
func insertContentsOf<S:SequenceType where Compatible(S)>(elements: S)
func insertContentsOf<Compatible(S)>(elements: S) // <- potential shorthand
}
…which isn’t the strongest motivating example on its own, but if you start to consider use cases where we will wind up having longer “where” clauses (and I think we will, over time) it may start paying its own way.
This probably falls under “minor feature” (and if added I’d hope the implementation picks a simple semantics for it), but something along these lines may do a decent job of addressing some of the same issues that motivate request to be able to write `Sequence<T>`.
More information about the swift-evolution
mailing list