import mir.format: text; import mir.algebraic_alias.json; JsonAlgebraic value = ["key" : [null.JsonAlgebraic, true.JsonAlgebraic, 100.JsonAlgebraic, 2.32.JsonAlgebraic].JsonAlgebraic]; // converts long numbers to a text form, ignores other types value.optionalTransformLeafs!( (long v) => v.text, (bool b) => b, // needs special overload for bool to get rid of implicit converion to long/double ); assert(value == ["key" : [null.JsonAlgebraic, true.JsonAlgebraic, "100".JsonAlgebraic, 2.32.JsonAlgebraic].JsonAlgebraic].JsonAlgebraic);
Behaves as transformLeafs but doesn't enforce at compile time that all types can be handled by the visiting functions.
The function ignores leafs that can't be handled by the visiting functions.