[swift-evolution] [Pitch] Moving where Clauses Out Of Parameter Lists
pyry.jahkola at iki.fi
Wed Apr 6 13:35:54 CDT 2016
> On 06 Apr 2016, at 21:30, Developer via swift-evolution <swift-evolution at swift.org> wrote:
> If you've ever gotten to the point where you have a sufficiently generic interface to a thing and you need to constrain it, possibly in an extension, maybe for a generic free function or operator, you know what a pain the syntax can be for these kinds of operations.
> Or, if you're feeling ambitious, even
> func anyCommonElements <T, U>
> where T : SequenceType, U : SequenceType,
> T.Generator.Element: Equatable, T.Generator.Element == U.Generator.Element
> (lhs: T, _ rhs: U) -> Bool
I would actually move them as far as after everything else, and right before the definition body. For the above function that would mean:
func anyCommonElements<T, U>(lhs: T, _ rhs: U) -> Bool
where T : SequenceType,
U : SequenceType,
T.Generator.Element == U.Generator.Element
That would make the definition look closer to what the call site looks like.
The same would work for generic types too:
public struct Dictionary<Key, Value>
where Key : Hashable
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution