RoseTree a -> (a -> Bool) -> RoseTree a
function filterSubtrees(pred, tree) {
  return new RoseTree(
    tree.root,
    function() {
      return tree.children().filter(function(subtree) {
        return pred(subtree.root);
      }).map(filterSubtrees.bind(null, pred));
    }
  );
}