# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .jl
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Julia 1.5.0
#     language: julia
#     name: julia-1.5
# ---

# ### Mill integration
#
# In this specific example, we show, how `HierarchicalUtils.jl` can be used with `Mill.jl` library

using Pkg
pkg"activate"
using HierarchicalUtils
using Mill

n1 = BagNode(BagNode(ArrayNode(randn(4,10)),[1:2,3:4,5:5,6:7,8:10]),[1:1,2:3,4:5])
n2 = ProductNode((ch1 = n1, ch2 = deepcopy(n1)))
ds = ProductNode((ch1 = n2, ch2 = deepcopy(n2), ch3 = deepcopy(n2)))

printtree(ds)

printtree(ds; htrunc=1)

printtree(ds; htrunc=2)

# Default printing (overriding `Base.show`) uses `htrunc = 3`

printtree(ds; htrunc=3)

nnodes(ds)

nleafs(ds)

NodeIterator(ds) |> collect

LeafIterator(ds) |> collect

TypeIterator(BagNode, ds) |> collect

pred(n::BagNode) = length(n.bags) > 4
pred(n::ProductNode) = :ch3 in keys(n.data)
pred(n) = false
PredicateIterator(pred, ds) |> collect

pred2(n::ArrayNode) = size(n.data, 2) > 5
pred2(n) = false
PredicateIterator(pred2, ds) |> collect

m = reflectinmodel(ds)

NodeIterator(m, ds) |> collect

StarcoderdataJupyterScriptsDedupFiltered