The OpenD Programming Language

tryTransformLeafs

Behaves as transformLeafs but doesn't enforce at compile time that all types can be handled by the visiting functions.

import mir.algebraic_alias.transform;
alias tryTransformLeafs(visitors...) = transformLeafsImpl!(tryVisit, naryFun!visitors)

Throws

Exception if naryFun!visitors can't be called with provided arguments

Examples

import mir.format: text;
import mir.algebraic_alias.json;
JsonAlgebraic value = ["key" : [true.JsonAlgebraic, 100.JsonAlgebraic, 2.32.JsonAlgebraic].JsonAlgebraic];

// converts long and double numbers to a text form, bool values is converted to `long`
value.tryTransformLeafs!((double v) => v.text, (long v) => v.text);
assert(value == ["key" : ["1".JsonAlgebraic, "100".JsonAlgebraic, "2.32".JsonAlgebraic].JsonAlgebraic].JsonAlgebraic);

Meta