Hello all,
I’m going through the open source beta version of the Dockyard Academy curriculum (GitHub - DockYard-Academy/beta_curriculum) and I’m doing some exercises about for comprehensions.
In one of these exercises I have to convert the following nested Enum.map into a comprehension with three generators:
Enum.map(1..3, fn a -> Enum.map(1..3, fn b -> {a, b} end) end)
# Result:
[[{1, 1}, {1, 2}, {1, 3}], [{2, 1}, {2, 2}, {2, 3}], [{3, 1}, {3, 2}, {3, 3}]]
My best guess has only two generators and results in one list without sublists:
for a <- 1..3, b <- 1..3, do: {a, b}
# Result:
[{1, 1}, {1, 2}, {1, 3}, {2, 1}, {2, 2}, {2, 3}, {3, 1}, {3, 2}, {3, 3}]
I assume the third generator (the one I am still missing) will create the 3 sublists. But I have no clue how this generator would look like. Any ideas?