package cat

type entry struct {
	name     string
	fqname   string
	content  string
	children []entry
}

func (e entry) filter(ok func(e entry) bool) entry {
	children := make([]entry, 0, len(e.children))
	for _, entry := range e.children {
		if !ok(entry) {
			continue
		}
		children = append(children, entry.filter(ok))
	}

	return entry{
		name:     e.name,
		fqname:   e.fqname,
		content:  e.content,
		children: children,
	}
}

func (e entry) traverse(lvl int, do func(e entry, lvl int)) {
	do(e, lvl)
	for _, entry := range e.children {
		entry.traverse(lvl+1, do)
	}
}
