Two easy pieces

bearophile bearophileHUGS at lycos.com
Tue Apr 2 04:27:23 PDT 2013


timotheecour:

> IMO, there's too little value in those ufcsWritef, ufcsWritefln,
> ufcsWriteln, ufcsWritefln to justify adding them. When does it 
> stop??

I have opened this thread, instead of asking for those functions 
in Bugzilla rightly because I don't know where it stops.


> Why not introduce 'tap', which is more generic and has been
> proposed before:
>
> something like this:
>
> T tap(alias fun,T)(T a){
>   fun(a);
>   return a;
> }
>
> Then:
>
> auto result = data.dostuff.domorestuff.tap!(a=>
> writef(fmt,a)).morestuff.finalstep;
>
> of course for non-formatted write it's even simpler:
>
> auto result = 
> data.dostuff.domorestuff.tap!writeln.morestuff.finalstep;

Because tap leads to a bit more verbose syntax, and because I've 
seen that in most cases what I want to put in tap is a printing 
:-)


> That being said, I believe std.algorithm.reduce DOES deserve 
> it's counterpart with reversed arguments,

There is a patch and discussions on this in Bugzilla and GitHub. 
So probably you will see a UFCS-friendly reduce.

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list