Created
June 4, 2014 05:41
-
-
Save tapi/c88175a020a232eb8a54 to your computer and use it in GitHub Desktop.
Generic types broken into separate lines
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func anyCommonElements <T, U where T: Sequence, U: Sequence, T.GeneratorType.Element: Equatable, T.GeneratorType.Element == U.GeneratorType.Element> (lhs: T, rhs: U) -> Bool { | |
for lhsItem in lhs { | |
for rhsItem in rhs { | |
if lhsItem == rhsItem { | |
return true | |
} | |
} | |
} | |
return false | |
} | |
anyCommonElements([1, 2, 3], [3]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func anyCommonElements | |
<T, U where T: Sequence, U: Sequence, T.GeneratorType.Element: Equatable, T.GeneratorType.Element == U.GeneratorType.Element> | |
(lhs: T, rhs: U) -> Bool | |
{ | |
for lhsItem in lhs { | |
for rhsItem in rhs { | |
if lhsItem == rhsItem { | |
return true | |
} | |
} | |
} | |
return false | |
} | |
anyCommonElements([1, 2, 3], [3]) |
@angusiguess Good call, Looks like this is what apple does internally https://github.com/apple/swift/blob/master/stdlib/public/core/Arrays.swift.gyb#L690-L693
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you wanted to go buck wild you could decompose it even further to roughly one constraint per line (assuming the whitespace doesn't make swift sad)