fuzion-lang.dev — The Fuzion Language Portal
JavaScript seems to be disabled. Functionality is limited.
Fuzion
•
Idioms
•
Idiom # 17: Create a Tree data structure
Idiom # 17: Create a Tree data structure
See
programming-idioms.org
:
Code
Code input
node(T type, val T, children Sequence (node T)) is
What are effects?
Running Example
Code input
node(T type, val T, children Sequence (node T)) is public redef as_string => (as_strings 0).as_string "\n" as_strings(d i32) => ["+-" + $val] ++ (children.flat_map String (c->c.as_strings d+1)).map s->"| $s" feuille(val String) => node val (list (node String)).empty t := node "C" [feuille "C++", feuille "C#" , feuille "Go" , node "Java" [feuille "Scala", feuille "Kotlin"], node "Perl" [feuille "Ruby", feuille "Raku"], node "Python" [feuille "Julia", feuille "Nim" ] ] say t
What are effects?
last changed: 2025-05-13
next: Idiom # 18: Depth-first traversing of a tree