Skip to content

Instantly share code, notes, and snippets.

@dennisvennink
Created August 13, 2017 08:56
Show Gist options
  • Save dennisvennink/e056bfbc4d46a297933ce50c36b3f2cb to your computer and use it in GitHub Desktop.
Save dennisvennink/e056bfbc4d46a297933ce50c36b3f2cb to your computer and use it in GitHub Desktop.
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