Value.canon: def of yaml-for-bend@0.1.1.0 Import: import yaml-for-bend@0.1.1.0/value.bend as Value Lines 108-137 of yaml-for-bend@0.1.1.0/value.bend: https://jend.leeeet.dev/read.txt?path=yaml-for-bend@0.1.1.0/value.bend&start_line=108&end_line=137 import Base # A value as text that two values share only when they are the same, to # look keys up by. A string is its length and text; "[" goes before each # item of a sequence and "]" after them, and "{" before each entry of a # mapping and "}" after them. def canon(v: Yaml) -> String: match v: case Null{}: "~" case Boolean{on}: Bool.pick(String, on, "t", "f") case Int{t}: "i" ++ t ++ ";" case Float{t}: "d" ++ t ++ ";" case Str{+t}: "s" ++ Nat.show(String.length(t)) ++ ":" ++ t case Seq{xs}: match xs: case Nil{}: "]" case Con{x, rest}: "[" ++ canon(x) ++ canon(Seq{rest}) case Mapping{es}: match es: case Nil{}: "}" case Con{Entry{k, x}, rest}: "{" ++ canon(k) ++ canon(x) ++ canon(Mapping{rest}) case Tagged{+tag, x}: "!" ++ Nat.show(String.length(tag)) ++ ":" ++ tag ++ canon(x) Uses (8): https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Bool.pick https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=List https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Nat.show https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=String https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=String.append https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=String.length https://jend.leeeet.dev/definition.txt?path=yaml-for-bend@0.1.1.0/value.bend&name=Entry https://jend.leeeet.dev/definition.txt?path=yaml-for-bend@0.1.1.0/value.bend&name=Yaml