.tupleof for static array

Paul Backus snarwin at gmail.com
Tue Aug 10 16:02:05 UTC 2021


On Tuesday, 10 August 2021 at 15:32:25 UTC, Dennis wrote:
> Thanks for this solution as well.
>
> On Tuesday, 10 August 2021 at 13:10:23 UTC, Paul Backus wrote:
>> Would definitely be nice to have this in the language, though.
>
> Do you know more use cases for this?

I've written range pipelines like this:

```d
someSourceRange
     .chunks(2)
     .map!(chunk => chunk.staticArray!2) // allows random access
     .each!(pair => doSomethingWith(pair[0], pair[1]));
```

Having to write `pair[0]` and `pair[1]` is a bit awkward, though. 
Normally I would use something like the following to bind each 
element to a separate parameter:

```d
alias apply(alias fun) = args => fun(args.tupleof);

/* ... */
     .each!(apply!((first, second) => doSomethingWith(first, 
second)));
```

...but `.tupleof` doesn't work with static arrays, so that 
doesn't compile.


More information about the Digitalmars-d-learn mailing list