How to hide a function return type in order to wrap several functions into an associated array?

tastyminerals tastyminerals at gmail.com
Sat Oct 3 18:26:31 UTC 2020


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.


More information about the Digitalmars-d-learn mailing list