<div dir="ltr">Another +1 to `where` at the end.<div class="gmail_extra"><br><div class="gmail_quote">On Wed, Apr 6, 2016 at 10:33 PM, Matt Whiteside via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">+1 to moving the `where` clause after the function signature.<br>
<br>
-Matt<br>
<div><div><br>
> On Apr 6, 2016, at 12:36, Joe Groff via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:<br>
><br>
><br>
>> On Apr 6, 2016, at 11:30 AM, Developer via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:<br>
>><br>
>> 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. For example, the Swift book implements this example to motivate where clauses<br>
>><br>
>> func anyCommonElements <T: SequenceType, U: SequenceType where T.Generator.Element: Equatable, T.Generator.Element == U.Generator.Element> (lhs: T, _ rhs: U) -> Bool<br>
>><br>
>> This is noisy and uncomfortable to my eyes, and almost impossible to align correctly. Per a short discussion on Twitter with Joe Groff and Erica Sadun, I'd like so see what the community feels about moving the where clause out of the angle brackets. So that example becomes<br>
>><br>
>> func anyCommonElements <T: SequenceType, U: SequenceType><br>
>> where T.Generator.Element: Equatable, T.Generator.Element == U.Generator.Element<br>
>> (lhs: T, _ rhs: U) -> Bool<br>
>><br>
>> Or, if you're feeling ambitious, even<br>
>><br>
>> func anyCommonElements <T, U><br>
>> where T : SequenceType, U : SequenceType,<br>
>> T.Generator.Element: Equatable, T.Generator.Element == U.Generator.Element<br>
>> (lhs: T, _ rhs: U) -> Bool<br>
>><br>
>> Thoughts?<br>
><br>
> I think this is a good idea, though I would put the `where` clause after the function signature:<br>
><br>
> func foo<T: Foo, U: Bar>(x: T, y: U) -> Result<T,U><br>
> where T.Foo == U.Bar /*, etc. */<br>
> {<br>
> }<br>
><br>
> As others noted, it's also appealing to do this for type declarations too:<br>
><br>
> struct Foo<T: Foo, U: Bar><br>
> where T.Foo == U.Bar<br>
> {<br>
> }<br>
><br>
> and that gives a consistent feeling with extensions and protocol declarations.<br>
><br>
> -Joe<br>
> _______________________________________________<br>
> swift-evolution mailing list<br>
> <a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
> <a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
<br>
_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div>Trent Nadeau</div>
</div></div>