Repository: plaid/sanctuary (js)

Issue:
check arguments.length in def function
Current behaviour:

```javascript
> S.or(true, true, true)
TypeError: Expecting a function in instanceof check, but got undefined
```

Desired behaviour:

```javascript
> S.or(true, true, true)
TypeError: ‘or’ requires two arguments; received three arguments
```

`S.or(true)(true, true)` should behave the same way.


Pull request description:
make exported functions throw if applied to too many arguments
Closes #81


Patch:
diff --git a/index.js b/index.js
index 9a05964..3a448fd 100644
--- a/index.js
+++ b/index.js
@@ -125,6 +125,10 @@
 
   var formatters = {
     '{}': R.identity,
+    '{card}': R.ifElse(R.lte(_, 10),
+                       R.nth(_, ['zero', 'one', 'two', 'three', 'four', 'five',
+                                 'six', 'seven', 'eight', 'nine', 'ten']),
+                       String),
     '{ord}': R.nth(_, ['first', 'second', 'third']),
     '{quote}': function(s) { return '\u2018' + s + '\u2019'; },
     '{repr}': R.toString,
@@ -188,6 +192,14 @@
         }
       }
 
+      if (arguments.length > paramIndexes.length) {
+        throw new TypeError(format(
+          '{quote} requires {card} {}; received {card} arguments',
+          [name, values.length, values.length === 1 ? 'argument' : 'arguments',
+           values.length + arguments.length - paramIndexes.length]
+        ));
+      }
+
       for (var argIndex = 0; argIndex < arguments.length; argIndex += 1) {
         var arg = arguments[argIndex];
         var paramIndex = paramIndexes[argIndex];


Test patch:
diff --git a/test/index.js b/test/index.js
index 2c40d03..a3e3db7 100644
--- a/test/index.js
+++ b/test/index.js
@@ -67,6 +67,33 @@ describe('invariants', function() {
     }
   });
 
+  it('exported functions throw if applied to too many arguments', function() {
+    assert.throws(function() { S.I(1, 2); },
+                  errorEq(TypeError,
+                          '‘I’ requires one argument; ' +
+                          'received two arguments'));
+
+    assert.throws(function() { S.K(1, 2, 3); },
+                  errorEq(TypeError,
+                          '‘K’ requires two arguments; ' +
+                          'received three arguments'));
+
+    assert.throws(function() { S.K(1)(2, 3); },
+                  errorEq(TypeError,
+                          '‘K’ requires two arguments; ' +
+                          'received three arguments'));
+
+    assert.throws(function() { S.K(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); },
+                  errorEq(TypeError,
+                          '‘K’ requires two arguments; ' +
+                          'received ten arguments'));
+
+    assert.throws(function() { S.K(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11); },
+                  errorEq(TypeError,
+                          '‘K’ requires two arguments; ' +
+                          'received 11 arguments'));
+  });
+
 });
 
 describe('classify', function() {