Skip to content

Commit 2bafef7

Browse files
committed
feat: allow plain function usage of fn.compose
1 parent 0943d8c commit 2bafef7

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,10 @@ Applies the functions in reverse argument-list order.
490490

491491
_f1.compose(f2, f3, f4)(…args) =def f1(f2(f3(f4(…arg))))_
492492

493+
`compose` can also be used in plain function form as:
494+
495+
_compose(f1, f2, f3, f4)(…args) =def f1(f2(f3(f4(…arg))))_
496+
493497
#### fn.copy() _(es5-ext/function/#/copy)_
494498

495499
Produces copy of given function

function/#/compose.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"use strict";
22

3-
var callable = require("../../object/valid-callable")
3+
var isValue = require("../../object/is-value")
4+
, callable = require("../../object/valid-callable")
45
, aFrom = require("../../array/from");
56

67
var apply = Function.prototype.apply
@@ -9,7 +10,8 @@ var apply = Function.prototype.apply
910

1011
module.exports = function (fnIgnored/*, …fnn*/) {
1112
var fns, first;
12-
fns = [this].concat(aFrom(arguments));
13+
var args = aFrom(arguments);
14+
fns = isValue(this) ? [this].concat(args) : args;
1315
fns.forEach(callable);
1416
fns = fns.reverse();
1517
first = fns[0];

test/function/#/compose.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@ var f = function (a, b) { return ["a", arguments.length, a, b]; }
44
, g = function (a) { return ["b", arguments.length].concat(a); }
55
, h = function (a) { return ["c", arguments.length].concat(a); };
66

7-
module.exports = function (t, a) { a.deep(t.call(h, g, f)(1, 2), ["c", 1, "b", 1, "a", 2, 1, 2]); };
7+
module.exports = function (t, a) {
8+
a.deep(t.call(h, g, f)(1, 2), ["c", 1, "b", 1, "a", 2, 1, 2]);
9+
a.deep(t(h, g, f)(1, 2), ["c", 1, "b", 1, "a", 2, 1, 2]);
10+
};

0 commit comments

Comments
 (0)