Mixin - to get to the content-type `MapResult!(__lambda1, int[]).MapResult`
Dennis Ritchie via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat May 30 12:19:19 PDT 2015
On Saturday, 30 May 2015 at 06:50:09 UTC, Ali Çehreli wrote:
> On 05/29/2015 06:07 PM, Dennis Ritchie wrote:
>
> > Hi,
> > This code prints the arrays:
> > [5]
> > [6]
> > [7]
> >
> > import std.stdio, std.algorithm;
> >
> > static int idx;
>
> Do you want to share that for the first element of every
> two-element array or do you want to start from 0 for every
> range?
I want to share...
> > void walk(R)(R range) {
> > while (!range.empty) {
> > range.front;
> > range.popFront;
> > ++idx;
> > }
> > }
>
> As a reminder, there is also the recent 'each', which is eager
> as well.
But I want to do this is to `map` :)
> > void main() {
> > [5, 6, 7].map!(a => [a].writeln).walk;
> > }
> >
> > How should I apply mixins to `range.front` to the program to
> print the
> > arrays:
> > [0, 5]
> > [1, 6]
> > [2, 7]
>
> Unless mixin required for another reason, there are other ways
> of achieving the same.
I just want to present the results of the intermediate
performance (which I plan to reach through the mixin)
`range.front` as a string, to then modify it with the help of
mixin to get directly to the array.
> > Ie I want to get something like this:
> >
> > void walk(R)(R range) {
> > while (!range.empty) {
> > // mixin(`[idx ~ "mixin("range.front")"[1 .. $]);`);
> > range.popFront;
> > ++idx;
> > }
> > }
> >
> > Can I do this?
> >
> > -----
> > Thank you for the function `walk` Mark Isaacson of
> presentation DConf 2015:
> > http://dconf.org/2015/talks/isaacson.pdf
>
> The following program produces the desired output twice. The
> first one starts from 0 for the index, the second one shares
> the index as in your code.
>
> import std.stdio, std.algorithm, std.range;
>
> void main() {
> zip(sequence!"n", [5, 6, 7])
> .map!(a => [a.expand])
> .each!writeln;
>
> static int idx;
>
> [5, 6, 7]
> .map!(a => [idx++, a])
> .each!writeln;
> }
Thank you for your examples, but I want to do something else.
Ie I want to access the intermediate generation `range.front`
with two mixins or by other means. `range` is of type
`MapResult!(__lambda1, int[])([5, 6, 7], null)` — I want to get
the generation of this intermediate, i.e. something like
`range.front` --> `[5].writeln` and present `[5].writeln` as a
string, to modify the line like so `[5].writeln` -->
`[5].writeln`[1 .. $] --> `[idx ~ `[5].writeln`[1 .. $]` -->
`[idx, 5].writeln` with the help of mixins. :)
I want to access the intermediate generation `range.front`. Is it
possible? :)
More information about the Digitalmars-d-learn
mailing list