-
Notifications
You must be signed in to change notification settings - Fork 396
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
when.map(...) with two parameters and node.lift(...) issue #420
Comments
Hey @nadvorny, yeah, this is an interesting issue. Originally, I like your idea of a Before 4.0, one option might be to add Any thoughts on that? Other ideas? Would like to get @unscriptable's thoughts as well. |
Ping @nadvorny, any thoughts? |
Actually I don't know which solution is the best for the library. Correct solution in my case is to use _.curryRight() function on lifted function to freeze second argument. There is one more problem with lifting a method of an object. Promise/A+ strictly states that var db = new cradle.Connection(...) Adding when.lift_something() functions to the library may cover these cases, May be these use cases should be just described in API documentation.
|
I agree. In fact, that's what I thought you were proposing when you suggested a solution similar to deferred's ability to limit arity. Do you feel like a lift variant that explicitly sets max arity is not a good solution? Another possible solution would be to remove the index parameter from
That's not quite true. Promises/A+ says that With respect to var db = new cradle.Connection(...);
// Obviously will not work:
var readCouchDb = db.view;
readCouchDb(...); // fails
// Also will not work, for the same reason as above:
readCouchDb = node.lift(db.view);
readCouchDb(...); // fails
// Works correctly:
readCouchDb = db.view;
readCouchDb.call(db, ...); // works
// Also works
readCouchDb = node.lift(db.view);
readCouchDb.call(db, ...); // works That said, in general, yes, lifting instance methods is tricky business, but not specifically because of anything when.js does in particular. |
With lodash 3.0 release and _.curryRight() being there this isn't a problem any more. Adding arity only to protect from when.map index passing seems excessive to me. On So we don't need arity with curryRight is there.
|
Cool, that's great news.
Agreed. I'll close this issue, and if we hit other situations where limiting arity is useful, we can revisit this discussion. |
When I lift node function with two parameters e.g.
fs.readFile(file, opts, callback)
lifted function can't be directly used in when.map, because map's mapper function is called with two parameters, and array index is passed into opts parameter. I have to wrap it into a lambda to prevent second parameter from passing.Lifting with partially applied parameters won't work because I need to apply or ignore the second one. Using lodash's
_.partialRight(...)
does not work either, because of how it works.Ideally I would like to be able not to check if parameters should be frozen or not. It seems that deferred library (https://github.com/medikoo/deferred) has a syntax for lift function that sets function arity, e.g. promisify(fs.readFile, 1) will ensure that lifted function will have only one parameter, and other ones will be ignored.
The text was updated successfully, but these errors were encountered: