Partial function application: Difference between revisions

m (→‎{{header|Kotlin}}: Inserted space before equals sign)
Line 982:
 
=={{header|JavaScript}}==
===ES5===
 
Higher order functions are part of the core architecture of JavaScript.
 
Line 1,039:
 
<pre>[[0, 2, 4, 6, 8], [0, 1, 4], [4, 8, 12, 16, 20, 24], [4, 16, 36, 64]]</pre>
 
===ES6===
<lang JavaScript>(() => {
'use strict';
 
// GENERIC FUNCTIONS ------------------------------------------------------
 
// curry :: ((a, b) -> c) -> a -> b -> c
const curry = f => a => b => f(a, b);
 
// map :: (a -> b) -> [a] -> [b]
const map = curry((f, xs) => xs.map(f));
 
 
// PARTIAL APPLICATION ----------------------------------------------------
 
const
f1 = x => x * 2,
f2 = x => x * x,
 
fs = map,
 
fsf1 = fs(f1),
fsf2 = fs(f2);
 
// TEST -------------------------------------------------------------------
return [
fsf1([0, 1, 2, 3]),
fsf2([0, 1, 2, 3]),
 
fsf1([2, 4, 6, 8]),
fsf2([2, 4, 6, 8])
];
})();</lang>
{{Out}}
<pre>[[0, 2, 4, 6], [0, 1, 4, 9], [4, 8, 12, 16], [4, 16, 36, 64]]</pre>
 
=={{header|Kotlin}}==
9,655

edits