The OpenD Programming Language

transformLeafs

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.

import mir.algebraic_alias.transform;
alias transformLeafs(visitors...) = transformLeafsImpl!(visit, naryFun!visitors)

Examples

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);

Meta