static Function<TreeCursor, Stream<Doc>> extractor(
            Function<TreeCursor, Doc> visitor,
            Function<TreeCursor, Stream<TreeCursor>> mapper,
            Function<TreeCursor, Stream<TreeCursor>> childrenSupplier
    ) {
        return (cursor) -> childrenSupplier.apply(cursor)
                .flatMap(c -> {
                    TreeType type = c.getTree().getType();
                    return type == TreeType.WS || type == TreeType.COMMENT ? Stream.of(c) : mapper.apply(c);
                })
                .flatMap(c -> {
                    // If the child extracts WS, then filter it down to just comments.
                    return c.getTree().getType() == TreeType.WS
                            ? c.getChildrenByType(TreeType.COMMENT).stream()
                            : Stream.of(c);
                })
                .map(visitor)
                .filter(doc -> doc != Doc.empty());
    }
Formats various kinds of brackets, dealing with interspersed whitespace and comments.
smithy-syntax/src/main/java/software/amazon/smithy/syntax/BracketFormatter.java