﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
16754	Consider changes in CKEDITOR.tools.array	Tade0		"`CKEDITOR.tools.array` 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).

== Why ==

A. Functions without implicit potential side-effects(`this`) are easier to reason about.
B. 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 => node.name == 'div');
const getParentP   = bind( getAscendant, null, node => node.name == '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 element.name == name;
      };
    },
    isLi = nameIs( 'li' ),
    lis  = filter( isLi, nodeList ); // list of ""li"" elements.

// As this:
var nameIs = function( name, element ) { return element.name == 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:
https://docs.python.org/2/library/functions.html
http://ramdajs.com/docs/

BTW: I volunteer to take care of this."	New Feature	new	Normal		General				
