{ "@context":[ "https://www.w3.org/ns/activitystreams", {"Hashtag":"as:Hashtag","sensitive":"as:sensitive"}, {"toot":"http://joinmastodon.org/ns#","focalPoint":"toot:focalPoint"} ], "published":"2024-11-04T00:41:30.152Z", "attributedTo":"https://epiktistes.com/actors/toddsundsted", "inReplyTo":"https://hachyderm.io/users/briankung/statuses/113419652500472605", "replies":"https://epiktistes.com/objects/FnBv0YbpE8A/replies", "to":["https://www.w3.org/ns/activitystreams#Public","https://hachyderm.io/users/briankung"], "cc":["https://epiktistes.com/actors/toddsundsted/followers"], "content":"
@briankung it's not as ergonomic as ruby, but in crystal you can declare recursive type aliases, which help with that specific problem:
alias RecursiveHash::Types = Hash(Char, RecursiveHash::Types) | String\n\nh = Hash(Char, RecursiveHash::Types).new\nh['a'] = Hash(Char, RecursiveHash::Types).new\nh['b'] = \"B\"\n\na = h['a'].as(Hash(Char, RecursiveHash::Types))\na['a'] = Hash(Char, RecursiveHash::Types).new\na['b'] = \"BB\"
the cost is some syntax to cast the union type to the specific recursive type, but you avoid static nested types.
", "mediaType":"text/html", "attachment":[], "tag":[ {"type":"Mention","name":"@briankung@hachyderm.io","href":"https://hachyderm.io/users/briankung"} ], "type":"Note", "id":"https://epiktistes.com/objects/FnBv0YbpE8A" }