Skip to content

Array/vector comprehension and AbstractTrees Leaves iterator #138

@pitsianis

Description

@pitsianis

Why the array comprehension behaves differently with the AbstractTrees.Leaves iterator?
In the following replacing Leaves(t) with, say, range(1,3,3), I do get the 2D array.

julia> using AbstractTrees

julia> t = [[1, 2], 3]
2-element Vector{Any}:
  [1, 2]
 3

julia> [(i,j) for i in Leaves(t), j in Leaves(t) ]
9-element Vector{Tuple{Int64, Int64}}:
 (1, 1)
 (2, 1)
 (3, 1)
 (1, 2)
 (2, 2)
 (3, 2)
 (1, 3)
 (2, 3)
 (3, 3)

julia> [(i,j) for i in collect(Leaves(t)), j in collect(Leaves(t)) ]
3×3 Matrix{Tuple{Int64, Int64}}:
 (1, 1)  (1, 2)  (1, 3)
 (2, 1)  (2, 2)  (2, 3)
 (3, 1)  (3, 2)  (3, 3)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions