Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#16754 closed New Feature (wontfix)

Consider changes in

Reported by: Tade0 Owned by:
Priority: Normal Milestone:
Component: General Version:
Keywords: Cc:

Description (last modified by Tade0) is an indispensable set of utilities when targeting such browsers as IE8.

There is room for improvement, though. One such improvement would be to arrange the parameters of the methods so that partial application is easier.

Proposed function signatures

 filter( fn, array )
forEach( fn, array )
    map( fn, array )
 reduce( fn, initialValue, array )
indexOf( value, array )

Note the lack of this argument. This can be realized by:

bind( fn, context, ...args )

which also enables partial application(functioning polyfills are available).


  1. Functions without implicit potential side-effects(this) are easier to reason about.
  2. Using partial application enables us to do composition and promotes code reusability.

Example 1: (ES2015 syntax for brevity)

function getAscendant( condition, node )

const getParentDiv = bind( getAscendant, null, node => == 'div');
const getParentP   = bind( getAscendant, null, node => == 'p');

// later
var parentDiv = getParentDiv( someNode );

// somewhere else
var parentP = getParentP( someOtherNode );

Example 2: (inspired by ticket:16745)

// Rewrite this:
var nameIs = function( name ) {
      return function( element ) {
        return == name;
    isLi = nameIs( 'li' ),
    lis  = filter( isLi, nodeList ); // list of "li" elements.

// As this:
var nameIs = function( name, element ) { return == name },
    isLi   = bind( nameIs, null, 'li' ),
    lis    = filter( isLi, nodeList ); // list of "li" elements.

These are of course rudimentary examples. One could conceivably go much further with this with currying.

Further reading

There's a large set of functions that are easy to implement and bring good value as long as composition is possible. For a list check out:


BTW: I volunteer to take care of this.

Change History (3)

comment:1 Changed 2 years ago by Tade0

Description: modified (diff)

comment:2 Changed 2 years ago by Tade0

Status: newconfirmed

comment:3 Changed 2 years ago by Marek Lewandowski

Resolution: wontfix
Status: confirmedclosed

As noted, we need standard Array API polyfills - as such developers are expecting those to match standard JS Array API.

I can see how there's an easy possibility to provide partial application-friendly APIs, simply by writing a plugin with such API, that would expose it as a dedicated namespace. So that's totally possible, we just don't need it in the core.

Last edited 2 years ago by Marek Lewandowski (previous) (diff)
Note: See TracTickets for help on using tickets.
© 2003 – 2019 CKSource – Frederico Knabben. All rights reserved. | Terms of use | Privacy policy