How to consume data from generator expression

From the combinations help

combinations(a, n)

Generate all combinations of n elements from an indexable object a. Because the number of combinations can be very large, this function returns an iterator object. Use
collect(combinations(a, n)) to get an array of all combinations.

When you are calling combinations(combinations(1:8, 4), 6) internal combinations(1:8, 4) is not an indexable object, because it is a generator. You have to materialize it in order to get the result. By the way it is better to use collect, instead of [x for x in b]

julia> a = collect(combinations(1:8, 4))  # materialization part, now `a` is an Array, which can be indexed
70-element Array{Array{Int64,1},1}:
 [1, 2, 3, 4]
 [1, 2, 3, 5]
 ⋮

julia> b = combinations(a, 6) # it's better not to collect this one, since it has 94 billions elements, if I am correct
2 Likes