@resultBuilder public enum TextBuilder { @inlinable public static func buildPartialBlock(first: N) -> N { first } @inlinable public static func buildPartialBlock(accumulated: N0, next: N1) -> NodeContainer { .init(nodes: [accumulated, next]) } @inlinable public static func buildArray(_ components: [N]) -> NodeContainer { .init(nodes: components) } @inlinable public static func buildBlock(_ components: N...) -> NodeContainer { .init(nodes: components) } @inlinable public static func buildEither(first component: N) -> EitherNode { .first(component) } @inlinable public static func buildEither(second component: N1) -> EitherNode { .second(component) } @inlinable public static func buildOptional(_ component: N?) -> N? { component } } public enum EitherNode: TextNode { case first(N) case second(N1) public var body: some TextNode { switch self { case let .first(node): return node.eraseToAnyTextNode() case let .second(node): return node.eraseToAnyTextNode() } } } public struct NodeContainer: TextNode { @usableFromInline var nodes: [any TextNode] @usableFromInline init(nodes: [any TextNode]) { self.nodes = nodes.reduce(into: [any TextNode]()) { array, next in if let many = next as? NodeContainer { array += many.nodes } else { array.append(next) } } } @inlinable public var body: some TextNode { nodes.reduce("") { $0 + $1.render() } } }