Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit e080e22cf1d015ba4c8df3c38bdd535433345fc8 @rook2pawn committed Jul 21, 2011
Showing with 58 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +35 −0 README.md
  3. +11 −0 index.js
  4. +11 −0 test.js
1 .gitignore
@@ -0,0 +1 @@
+.npmignore
35 README.md
@@ -0,0 +1,35 @@
+partial
+=======
+
+is simple to use
+
+ var partial = require('partial');
+ var foo = function(x,y,z) { return (x*y) + z }
+
+ var bar = partial(foo);
+
+and we're done! Now we can simply say
+
+ bar(2,3)(4); // 10
+ bar(2)(3,4); // 10
+
+ var fix = bar(2,3);
+ fix(4); // 10
+
+
+usage
+-----
+Simply pass any function to partial, and if you wish, any arguments you want to fix.
+
+ var bar = partial(foo);
+ var baz = bar(2,3);
+
+is identical to
+
+ var baz2 = partial(foo,2,3);
+
+
+both can be used like so:
+
+ baz(4); // 10
+ baz2(4); // 10
11 index.js
@@ -0,0 +1,11 @@
+var exports = module.exports = function() {
+ var fn = arguments[0];
+ var args = [].concat.apply([],arguments).slice(1);
+ return function() {
+ if ((arguments.length + args.length) >= fn.length) {
+ return fn.apply(fn, [].concat.apply(args,arguments));
+ } else {
+ return exports(fn,[].concat.apply(args,arguments));
+ }
+ };
+};
11 test.js
@@ -0,0 +1,11 @@
+var partial = require('./index.js');
+var m3 = function(x,y,z) {
+ return (x*y) + z;
+};
+
+var foo = partial(m3);
+console.log(foo(2,3,4)); // 10
+console.log(foo(2,3)(4)); //10
+
+var bar = foo(2,3);
+console.log(bar(4)); // 10

0 comments on commit e080e22

Please sign in to comment.