Skip to content

Latest commit

 

History

History
36 lines (25 loc) · 786 Bytes

auto-currying.md

File metadata and controls

36 lines (25 loc) · 786 Bytes

Auto-currying

Promise operations have fixed arities to support auto-currying.

With auto-currying all the following instructions would return the same result:

add(1, 2, 3); // 6
add(1, 2)(3); // 6
add(1)(2)(3); // 6

Thus, you can store any intermediate function to reuse it :

const add1 = add(1);
add1(2, 3); // 6

Example with delay operation:

const { delay } = require("@arpinum/promising");

const delay1s = delay(1000);
delay1s(console.log)("I am", "late");

Example with map operation operation:

const { map } = require("@arpinum/promising");

const mapRound = map(Math.round);
mapRound([1.2, 5.7, 9.9]).then(console.log); // [ 1, 6, 10 ]