Proposal: Extension Methods
Chris Wright
dhasenan at gmail.com
Sun May 18 07:00:22 PDT 2008
Nick Sabalausky wrote:
> I was just looking through the documentation on some of the Phobos stuff
> that's new in D2, and at pipe! and compose! in particular. This is kind of
> nice (from docs):
>
> int[] a = pipe!(readText, split, map!(to!(int)))("file.txt");
>
> Not to nag about extension methods (well, ok, yes: to nag ;) ), but with
> extension methods (regardless if they're explicit or implicit), that could
> be cleaned up to:
>
> int[] a = "file.txt".readText().split().map!(to!(int)))();
Or: auto a = "file.txt".readText.split.map!(to!(int)));
Now, since "file.txt" is an array, readText returns an array, and split
returns an array, you can currently do this. Were any of those a class,
struct, or scalar, you'd be SOL until uniform call syntax is implemented.
I wonder if uniform call syntax could be used the opposite way:
class A
{
void foo(){}
}
foo(new A);
More information about the Digitalmars-d
mailing list