Ruby-style "each" in D?
w0rp
devw0rp at gmail.com
Fri Mar 21 11:29:00 PDT 2014
On Friday, 21 March 2014 at 11:03:01 UTC, monarch_dodra wrote:
> //----
> foreach ( a ;
> chain(iota(0, N), only(N), iota(0, N).retro) )
> {
> writeln(' '.repeat(N - a), '*'.repeat(a*2+1)))
> }
> //----
I don't think it's so complicated. It's just taking this.
someRange.mungeItHowever.each!useIt;
Instead of writing this.
foreach(someThing; someRange.mungeItHowever) someThing.useIt;
Maybe it's like the difference between writing foo(bar) and
bar.foo. It can just look a little nicer.
More information about the Digitalmars-d
mailing list