Scoped binding of a method to an object
Benjamin (Inglor) Gruenbaum
inglor at gmail.com
Tue Oct 15 13:28:36 PDT 2013
Wait, I think maybe I did not understand what you meant before.
Are we talking about using `::` for infixing the first parameter of the
function? As in `func(a,b,c)` being the same as `a::func(b,c)` ?
Would that let us do `[1,2,3,4,5]::_.reduce(x=>x%2 ===
0)::_.map(x=>2*x)::._.reduce(x,y) => x+y))`? That could actually be pretty
nice, and if that lets us do extension methods that could also be pretty
Is this what you meant by `::` and then having extension methods as an
If not, can you elaborate on `::`? If yes, I'm all ears. This sounds like
an interesting syntactic sugar that could help. It doesn't solve the
problem of putting the method where it belongs but it does solve chaining
On Tue, Oct 15, 2013 at 7:58 PM, Russell Leggett
<russell.leggett at gmail.com>wrote:
>> > If we didn't have :: (which we don't now), I think people will
>> continue to simply use functions like what underscore does. Personally, I'm
>> ok with that
>> I think using stuff like _.shuffle([1,2,3,4,5]) is not as nice and worse
>> than [1,2,3,4,5].shuffle() . Especially in a more functional interface that
>> does not return the original array (we can even have a generator here).
> I prefer it too, which is why I suggested :: - its not as nice in terms of
> needing to understand a new operator, but it does allow you to think about
> it in a more OO way, and it allows for forward chaining without wrappers.
>> Let's say I have an array [1,2,3,4,5], I want to filter the odd ones,
>> double the remaining elements and then sum the result. (This is obviously
>> not a real use case, but I think we both know there are such use cases)
>> The big issue I see here is chaining.
>> `_.reduce(_.map(_.filter([1,2,3,4,5],x=>x%2 === 0),x=>2*x),(x,y)=>x+y)`
>> Is a lot less readable than
> Speaking of wrappers - underscore does have the chain method which wraps
> and allows for chaining. Not ideal, but better, and people are comfortable
> with it - I mean look at jQuery.
>> Having another invocation syntax like `::` sounds like a __huge__
>> overhead to me.
>> Its not an invocation syntax, its fairly trivial binding sugar which can
> be used to apply functions to objects as the receiver without modifying the
> object, which is precisely what you want to be able to do with SOE even if
> you don't like the syntax.
> - Russ
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss