Extra functions on Arrays, Maps, etc..

"Ionuț G. Stan" ionut.g.stan at gmail.com
Tue Apr 10 01:58:49 PDT 2012


On 09/Apr/2012 23:55, Brendan Eich wrote:
> Erik Arvidsson wrote:
>> Fortunately all the Array.prototype methods are generic so it all just works.
>
> Except without a new protocol (opt-in, for backward compat) the pure
> methods all create a new Array instance to return, not a new NodeList.
> Is that considered potentially problematic?

Sometimes the reverse might be slightly unexpected at first sight. For 
example mapping over a Set in Scala:

   scala> Set("foo", "bar", "bazooka").map(word => word.length)
   res4: scala.collection.immutable.Set[Int] = Set(3, 7)

One might expect the result to be a collection like [3, 3, 7] whereas 
the result is a new set in which 3 occurs just once.

Just something to keep in mind.

-- 
Ionuț G. Stan  |  http://igstan.ro


More information about the es-discuss mailing list