<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>Certainly, I'd argue that it's generally better practice to do the work<br>
in popFront, because front does frequently gets called multiple times, and you<br>
almost always end up calling front if you call popFront.<br></blockquote><div><br></div><div>Actually, the way phobos is designed, often times it's easier to specify what front does, eg with map and related functions.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
It's possible that map, joiner, and or array could use some efficiency<br>
improvements, but I wouldn't consider the difference in the number of calls to<br>
front to be a bug. At most, it might indicate that there are some optimization<br>
opportunities in one or more of those functions, and it might even be that the<br>
differing number of calls makes sense when you actually dig into the source<br>
code. I'd have to go digging to know for sure.<br></blockquote><div><br></div><div><br></div><div>it's not just an issue of optimization opportunities, it's an issue of correctness and principle of least surprise; the code I shown was simplied from a larger bug I had where I was doing side effects in the map lambda that were meant to be called once per element instead of multiple times. <div>
<br></div></div><div><div>Is there a convenient to achieve the same effect as this:<br></div><div><div><br></div><div>elements.map ! fun_with_side_effects . joiner . do_something_with_result</div><div><br></div><div>but such that fun_with_side_effects is called only once per element ? (likewise with other functions that operate on ranges).</div>
<div><br></div><div>As it is, joiner and friends is dangerous to use with generic code because of that. std.array.{array,join} doesn't have this issue.</div><div><br></div><div>why not modify joiner (+friends) so that:</div>
<div>if front() is pure, allow calling it multiple times</div><div>if not, make sure to call it only once per element</div><div><br></div></div></div></div></div></div>