On Sunday, 27 September 2020 at 20:03:21 UTC, Paul Backus wrote:
On Sunday, 27 September 2020 at 18:54:11 UTC, tastyminerals wrote:
[...]

You can use an Algebraic [1] or SumType [2] for this:

alias Feature = SumType!(ulong, double, bool);

Feature numberOfPunctChars(string text)
{
    // ...
    return Feature(cnt);
}

Feature ratioOfDigitsToChars(string text)
{
    // ...
    return Feature(ratio);
}

Feature hasUnbalancedParens(string text)
{
    // ...
    return Feature(!isBalanced);
}

[1] http://dpldocs.info/experimental-docs/std.variant.Algebraic.html
[2] https://code.dlang.org/packages/sumtype

Nice, thanks. Never used it, shall take a look.

Reply via email to