import mir.format: text; import mir.algebraic_alias.json; JsonAlgebraic value = ["key" : ["str".JsonAlgebraic, 2.32.JsonAlgebraic, null.JsonAlgebraic].JsonAlgebraic]; // converts all leavs to a text form value.transformLeafs!text; assert(value == ["key" : ["str".JsonAlgebraic, "2.32".JsonAlgebraic, "null".JsonAlgebraic].JsonAlgebraic].JsonAlgebraic); value = ["key" : ["str".JsonAlgebraic, 2.32.JsonAlgebraic, true.JsonAlgebraic].JsonAlgebraic].JsonAlgebraic; /// converts only bool values value.transformLeafs!( (bool b) => b.text, v => v, // other values are copied as is ); assert(value == ["key" : ["str".JsonAlgebraic, 2.32.JsonAlgebraic, "true".JsonAlgebraic].JsonAlgebraic].JsonAlgebraic);
Transforms algebraics leafs recursively in place, ensuring that all leaf types are handled by the visiting functions.
Recursion is done for This[], StringMap!This, This[string], and Annotated!This types.