Last active
May 22, 2017 15:10
-
-
Save KentaKudo/8843392ce13dbfeb66f00e08625a538b to your computer and use it in GitHub Desktop.
Convert the order of array and needle
This file contains 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
// standard | |
[1,2,3,4,5,6,7].contains(3) | |
// alternative | |
protocol A { | |
func `is`(in haystack: [Self]) -> Bool | |
func `is`(in haystack: Self...) -> Bool | |
} | |
extension A where Self: Comparable { | |
func `is`(in haystack: [Self]) -> Bool { return haystack.contains(self) } | |
func `is`(in haystack: Self...) -> Bool { return self.is(in: haystack) } | |
} | |
extension Int: A {} | |
3.is(in: [1,2,3,4,5,6,7]) | |
3.is(in: 1,2,3,4,5,6,7) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment