Partial label maps on rose trees #
RoseTree.filterMap (f : α → Option β) relabels a rose tree along f,
recursively dropping every subtree whose root label maps to none; the
result is none iff the root itself is dropped. The rose-tree analogue
of List.filterMap, with UnorderedTree.filterMap its descent
through the Perm quotient.
Main definitions #
RoseTree.filterMap,RoseTree.filterMapList— the mutual tree / children-list partial maps.UnorderedTree.filterMap— the descent through thePermquotient.
Main results #
RoseTree.filterMap_map—filterMap f (map g t) = filterMap (f ∘ g) t.RoseTree.filterMap_some— a total map drops nothing:filterMap (fun a => some (g a)) t = some (map g t).
Partially relabel a rose tree: subtrees whose root label maps to
none are dropped, recursively; none iff the root itself is
dropped.
Equations
- RoseTree.filterMap f (RoseTree.node a cs) = Option.map (fun (b : β) => RoseTree.node b (RoseTree.filterMapList f cs)) (f a)
Instances For
Children-list companion of RoseTree.filterMap: partial map over a
list of trees, dropping the none results.
Equations
- RoseTree.filterMapList f [] = []
- RoseTree.filterMapList f (c :: cs) = match RoseTree.filterMap f c with | none => RoseTree.filterMapList f cs | some t => t :: RoseTree.filterMapList f cs
Instances For
filterMapList on a singleton: the head's partial map as a list.
RoseTree.filterMapList agrees with List.filterMap of the
per-tree partial map.
RoseTree.filterMapList distributes over list concatenation.
Composition with total maps #
Children-list companion of RoseTree.filterMap_map.
Children-list companion of RoseTree.filterMap_some.
Descent to UnorderedTree #
RoseTree.filterMap f ∘ UnorderedTree.mk is well-defined modulo Perm:
Perm permutes children, filterMapList commutes with permutations up
to List.Perm, and child-list order collapses at the UnorderedTree.mk
level.
Partially relabel a UnorderedTree tree, dropping subtrees whose root
label maps to none.
Equations
- UnorderedTree.filterMap f = Quotient.lift (filterMapQuotient✝ f) ⋯
Instances For
The Sum.getLeft? roundtrip #
UnorderedTree version of RoseTree.filterMap_getLeft?_map_inl.