Re: std.algorithm.map with side-effects

2014-12-05 Thread bearophile via Digitalmars-d-learn
Joseph Rushton Wakeling: Yes, I remember you requesting that. Were there ever any PRs, or was it just spec? I think two different persons implemented something like "each". A similar function is used very commonly in F#, where it's named "iter": http://msdn.microsoft.com/en-us/library/ee34

Re: std.algorithm.map with side-effects

2014-12-05 Thread evenex via Digitalmars-d-learn
map won't actually compute anything until you start asking for individual elements with front, back, or opIndex. Personally I like to use something like ref transform (alias action, R, T...)(ref R range, T addl_args) { range = action (range, addl_args); return range; } to

Re: std.algorithm.map with side-effects

2014-12-05 Thread Joseph Rushton Wakeling via Digitalmars-d-learn
On 06/12/14 00:58, bearophile via Digitalmars-d-learn wrote: Joseph Rushton Wakeling: Can anyone advise why, map is lazy, like most other ranges. Ah, I see. That function would only be called on consumption of the results of the map. Lazy higher order functions like map/filter should b

Re: std.algorithm.map with side-effects

2014-12-05 Thread bearophile via Digitalmars-d-learn
Joseph Rushton Wakeling: Can anyone advise why, map is lazy, like most other ranges. and whether there's a nice range iteration option to ensure that this function gets called using each element of the filteredRange? Lazy higher order functions like map/filter should be used only with p

std.algorithm.map with side-effects

2014-12-05 Thread Joseph Rushton Wakeling via Digitalmars-d-learn
Here's a little experiment I was trying out earlier today in order to try and convert foreach-style code to using UFCS of ranges: // import std.algorithm, std.range, std.stdio; void main() { size_t s = 0; void essify(size_t n) { w