import std.stdio;
ubyte[] extend(in uint[] arr)
{
ubyte[] result;
foreach (n; arr)
{
if (n < 10)
{
result ~= n;
// source/app.d(10,11): Error: cannot
append type const(uint) to type ubyte[]
}
else
{
import std.conv : to;
foreach (digit; n.to!string)
{
result ~= digit.to!ubyte;
}
}
}
return result;
}
unittest
{
import std.algorithm : equal;
assert(extend([1, 25, 70, 0]).equal([1, 2, 5, 7, 0, 0]));
}
How can I get around this? I want to ensure that the array is not
mutated in the function in the signature too.