Expose a length property for curried functions#477
Expose a length property for curried functions#477dalefrancis88 merged 2 commits intoevilsoft:masterfrom
Conversation
d2a6d40 to
07d6dda
Compare
evilsoft
left a comment
There was a problem hiding this comment.
Just got one question on the use of configurable, but other than that a welcome addition.
src/core/curry.js
Outdated
| }) | ||
|
|
||
| Object.defineProperty(curried, 'length', { | ||
| configurable: true, |
There was a problem hiding this comment.
Why allow this to be configurable?
I would think that this will always be Number and should never be able to be deleted.
There was a problem hiding this comment.
This is a good question and I wish I had a good answer in response.
I literally took inspiration from the following in DevTools:
Object.getOwnPropertyDescriptors(() => {}).length
I'm more than happy to remove this or set it to false.
There was a problem hiding this comment.
I would say, remove it for now. I cannot see a need for it to be configurable.
It defaults to false so no need to explicitly set it (unless you want to communicate that this property is in debate?)
There was a problem hiding this comment.
Excellent! I've remove the property. Thanks for bringing this one up because I wasn't entirely sure whether it should be included or not 👍
This will only be for the "last" fn passed in yeah? For instance this would report as (1), even though it is really (2) // fn :: String -> Array -> Array
const fn = curry(
compose(map, objOf)
) |
|
@evilsoft Hmmm, that's an interesting one. The length of a function with implicit parameters ( If my thinking is on track, the arity of the fn returned by |
|
There would be a similar discrepancy with functions that employ default values, since the
Source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/length That is to say, I believe this implementation is consistent with expectations as per the spec. What do you think? |
|
In addition to this, I wonder whether we could fix the arity of composed functions to the arity of the right-most function in the composition? Just a thought. |
So this will open up a can of worms, especially if we use this for determining argument application. Because we currently allow an n-ary interface (uncurried) of the right-most function that above function will not be applied properly. When curried, if it reports a length of (2) it will apply it to We are currently debating limiting arguments to |
Yep totes! Good call! |
It is 💯, I am just saying that when using this property, we should be aware that this does not pertain to the overall function as a whole, just the current "frame" of the curry stack. So if we are gathering and applying arguments before running a side-effect or something, we cannot use this length as the sole indication that we now have all of our arguments and are ready to apply them. |
07d6dda to
d29255f
Compare
Oh yes! Absolutely. |
evilsoft
left a comment
There was a problem hiding this comment.
Unless @dalefrancis88 says 👻 to anything I would say this GTG!
dalefrancis88
left a comment
There was a problem hiding this comment.
I think this is fine to add, this only adds value. I know that this has popped up a few times.
I think @evilsoft has covered some really great concerns and they've been addressed, i'm curious to see what will come from this being added.
While working through a first-pass on what
Async.fromNodemight look like with its incoming parameter curried (see #478), I noticed that I was unable to check for a length on incoming curried functions.With this change in place the code for allowing curried functions with
Async.fromNodepasses the tests.What do you think about this change to
currywhere we expose the length oncurriedof the originalfnthat was passed in?