what wrong with this alias
Salih Dincer
salihdb at hotmail.com
Sun Jan 8 12:35:17 UTC 2023
On Sunday, 8 January 2023 at 09:45:09 UTC, Krzysztof Jajeśnica
wrote:
> ## Simple explanation
>
> `to!string` is a function expecting 1 argument, which you're
> not providing in your alias. Convert your alias to a lambda
> expression:
>
> ```D
> alias comb = x => x.to!string.map!q{a - '0'}
> ```
A logical solution...
Since your goal is to manipulate numbers, it is possible to
convert directly to char type:
```d
import std.algorithm : map, sum;
import std.conv : toChars;
alias comb = (uint x) => x.toChars.map!"a - '0'";
void main()
{
auto s = 2234.comb.sum;
assert(s.comb.sum == 2);
}
```
SDB at 79
More information about the Digitalmars-d-learn
mailing list