Created
August 13, 2017 08:56
-
-
Save dennisvennink/e056bfbc4d46a297933ce50c36b3f2cb to your computer and use it in GitHub Desktop.
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
let s1 = [1, 2] | |
let s2 = [3, 4, 5] | |
func product <Sequence1: Sequence, Sequence2: Sequence> (_ s1: Sequence1, _ s2: Sequence2) -> AnySequence<(Sequence1.Element, Sequence2.Element)> { | |
return AnySequence( | |
s1.flatMap { e1 in | |
s2.map { e2 in | |
print(e1, e2) | |
return (e1, e2) | |
} | |
} | |
) | |
} | |
for (e1, e2) in product(s1, s2) { | |
if e1 == 1 && e2 == 3 { | |
break | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment