Can this be done? Defining type as in this Scala sample code

Bienlein jeti789 at web.de
Wed Feb 28 08:44:22 UTC 2018


On Monday, 26 February 2018 at 16:53:39 UTC, drug wrote:
> you can do something like this (https://run.dlang.io/is/RYR5Dm):
> ```
> import std.algorithm : sum;
> import std.range : only;
> import std.stdio : writeln;
> import std.typecons : tuple;
>
> void main()
> {
>     {
>         auto list = tuple(1, 2.4, 5);
>         auto sum = list.expand.only.sum;
>         writeln(sum);
>     }
>
>     {
>         // do not compile
>         /*
>         auto list = tuple(1, 2.4, 5, "123");
>         auto sum = list.expand.only.sum;
>         writeln(sum);
>         */
>     }
> }
> ```

This looks good. It's not completely transparent, because of this 
"expand.only" thing. But I guess it can be done to hide it. 
Thanks for this one.


More information about the Digitalmars-d mailing list