🌐 REASONML PACT DIFFICULTY: Adept Structural

Composite in ReasonML

Recursive variant types for hierarchical DOM hexes.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Composite
ARCANUM SCHOOL: Illusion // Phantasm
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// REASON PATTERN //
type uiNode =
  | Text(string)
  | Box(list(uiNode));

let rec renderNode = (n) =>
  switch (n) {
  | Text(s) => s
  | Box(children) => "[" ++ String.concat(", ", List.map(renderNode, children)) ++ "]"
  };

Trees of UI components form a composite structure, seamlessly traversed by recursive functions and pattern matching.

Runic Tags: #reason #composite #structural