-
-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
systematic type checking #50
Conversation
'requires a value of type', | ||
/^function (\w*)/.exec(typePair[1])[1], | ||
'as its', | ||
['first', 'second', 'third', 'fourth', 'fifth'][typePair[0]], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you really dont like functions that take many arguments ah... what happens if you're out of bound here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is only used internally, so we needn't support arities greater than the maximum arity of a Sanctuary function. This is currently three, so we could get away with ['first', 'second', 'third']
. If we decide to expose this function at some point we'll need to update it to handle arbitrary arities.
well, this code is obviously beyond my understanding, but I very much like the more detailed error logging which I hit all the time :) |
I hope it will be as useful in practice as it is in theory. :) |
Looks pretty cool 🐪 |
I'm sure it will! |
var $typePairs = []; | ||
for (var idx = 0; idx < args.length; idx += 1) { | ||
var typePair = typePairs[idx]; | ||
if (args[idx] === _) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to wait until Ramda v0.15.0 is available so that I can update this to:
if (args[idx] != null && args[idx]['@@functional/placeholder'] === true) {
See ramda/ramda#1156 for details.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⚡
This will change lives. |
This is a really nice change and will make working with Sanctuary a more pleasant experience. 👍 |
Very impressive, David. Really looking forward to using this when it is merged. |
d8da0ed
to
e33097c
Compare
e33097c
to
81fe9e4
Compare
case 2: return function(a, b) { return f.apply(this, arguments); }; | ||
case 3: return function(a, b, c) { return f.apply(this, arguments); }; | ||
} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
R.arity
was deprecated in v0.15.0, so we must provide this ourselves. It's not onerous since we don't export any functions with arity greater than three.
systematic type checking
Sanctuary currently does type checking in a few places (as those of use who've seen
Pattern match failure
logged to our console can attest). This pull request addresses two problems with the status quo:See what happens when we provide arguments to a function in the wrong order:
Types are checked as arguments are applied:
This approach was proposed by @paldepind in ramda/ramda#1125 (comment).
It's pleasing that index.js did not grow significantly, despite the fact that we now 🍛 our own functions.