On Fri, 04 May 2012 16:05:25 -0400, Jakob Ovrum <jakobov...@gmail.com> wrote:

On Friday, 4 May 2012 at 19:17:13 UTC, Steven Schveighoffer wrote:
This one:

Collection c = new Collection();
c = c.filter!(x => x < 3).toCollection();

filter isn't a property of c, it's a range-producing function. So I only have to define filter once, as a range accepting, range producing function. And any container type, as long as it can produce a range, can use this as a pseudo method (via UFCS) to make a filtered copy of itself.

-Steve

That's not a real example, that's pretty much the same example I provided below the part you quoted.

First, what would you consider a real example?

Second, there's an important piece of the use case that your sample lacks -- Jacob is rebinding the result back to the original item.

So for example, I could see code like this:

void displayResults(Container c)
{
  if(maxvalue)
     c = c.filter!(x => x < maxvalue).makeContainer!Container();

  // proceed to display elements from c
}

-Steve

Reply via email to