type
    Node = ref object of RootObj
        id: string
    
    Container = ref object of Node
        scope: seq[Node]
    
    View = ref object of Node
        name: string
        initNode: Node
        scope: seq[Node]  
let 
    first = Node(id: "InitNode")
    other = Node(id: "Hi")
    container = 
        Container(scope: @[Node(id: "Node1"), Node(id: "Node2")])
    # It is necessary to cast to Node here if you initialize a seq like this
    view = View(name:"View1", initNode: first, scope: @[container.Node, other])
proc forEach(node: Node) =
    if node of Container:
        let c = Container(node)
        for node2 in c.scope:
            forEach(node2)
    elif node of View:
        let v = View(node)
        forEach(v.initNode)
        for node2 in v.scope:
            forEach(node2)
    else:
        echo "Node id: ", node.id
forEach view