Append to 'map' result
Jean-Louis Leroy via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Jul 4 16:57:28 PDT 2017
On Tuesday, 4 July 2017 at 23:26:28 UTC, H. S. Teoh wrote:
> On Tue, Jul 04, 2017 at 11:27:25PM +0000, Jean-Louis Leroy via
> Digitalmars-d-learn wrote:
>> I want to create a range that consists of the result of a map()
>> followed by a value, e.g.:
>>
>> int[] x = [ 1, 2, 3];
>> auto y = map!(x => x * x)(x);
>> auto z = y ~ 99; // how???
>>
>> I have tried several variations: convert 99 to a dynamic
>> array, to a range, convert range to dynamic array (couldn't
>> even figure that one); to no avail.
> [...]
>
> Try:
>
> auto z = chain(y, only(99));
Thanks!
However, when I try to use this construct in my real code, I
still have a problem:
// k is a ClassInfo
chain(map!(i => i.classinfo)(k.interfaces), only(k.base))
meth.d(311): Error: template std.range.chain cannot deduce
function from argument types !()(MapResult!(__lambda3,
Interface[]), OnlyResult!(TypeInfo_Class, 1LU)), candidates are:
/usr/include/d/std/range/package.d(795):
std.range.chain(Ranges...)(Ranges rs) if (Ranges.length > 0 &&
allSatisfy!(isInputRange, staticMap!(Unqual, Ranges)) &&
!is(CommonType!(staticMap!(ElementType, staticMap!(Unqual,
Ranges))) == void))
More information about the Digitalmars-d-learn
mailing list