I want to learn more about functional programming. I decided to start with an "easy" example: getting the Cartesian product of two arrays, as in this code:
let xArray = [1, 2, 3]
let yArray = [4, 5, 6]
var pairs: [(Int, Int)] = []
for x in xArray {
for y in yArray {
pairs.append((x, y))
}
}Now, many hours later, I still haven't figured out how to do this in a functional way. Perhaps I should stick to declarative programming.