A Small Contribution to Phobos

Brad Anderson eco at gnuk.net
Sat Jun 1 22:33:46 PDT 2013


On Sunday, 2 June 2013 at 04:10:15 UTC, Jonathan M Davis wrote:
> On Sunday, June 02, 2013 04:57:53 Meta wrote:
> The callable bit won't work. It'll just call front. You'd have 
> to do something
> like
>
> static if(isCallable!(ElementType!R))
>     r.front()();
>
> Also, if front were pure, then calling it and doing nothing 
> with its return
> value would result in a compilation error. The same goes if the 
> element type
> is a pure callable.

Calling front is kind of the point of exhaust(), otherwise you'd 
use takeNone().  You wouldn't use this if front were pure because 
the only reason you'd want exhaust is if you were (ab)using side 
effects (like I was the other day on D.learn).  Having it error 
out if you were using it on a range with pure front() is actually 
a good thing because you've made some error in your reasoning if 
you think you want exhaust() to run in that situation. 
processSideEffects() is probably too long of name.

>  And even if this did work exactly as you intended. I think
> that assuming that someone exhausting the range would would 
> what front returns
> to be called is a bad idea. Maybe they do, maybe they don't, 
> I'd expect that
> in most cases, they wouldn't. If that's what they want, they 
> can call map
> before calling exhaust.
>

Sticking a map before exhaust without it calling front() would 
accomplish nothing. I know this because my own little toy eat() 
just called popFront() originally on a Map range and nothing 
happened.  You'd be skipping map's function if you don't call 
front.


More information about the Digitalmars-d mailing list