{"action":"created","issue":{"url":"https://api.github.com/repos/cujojs/when/issues/420","labels_url":"https://api.github.com/repos/cujojs/when/issues/420/labels{/name}","comments_url":"https://api.github.com/repos/cujojs/when/issues/420/comments","events_url":"https://api.github.com/repos/cujojs/when/issues/420/events","html_url":"https://github.com/cujojs/when/issues/420","id":54712832,"number":420,"title":"when.map(...) with two parameters and node.lift(...) issue","user":{"login":"nadvorny","id":294929,"avatar_url":"https://avatars.githubusercontent.com/u/294929?v=3","gravatar_id":"","url":"https://api.github.com/users/nadvorny","html_url":"https://github.com/nadvorny","followers_url":"https://api.github.com/users/nadvorny/followers","following_url":"https://api.github.com/users/nadvorny/following{/other_user}","gists_url":"https://api.github.com/users/nadvorny/gists{/gist_id}","starred_url":"https://api.github.com/users/nadvorny/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nadvorny/subscriptions","organizations_url":"https://api.github.com/users/nadvorny/orgs","repos_url":"https://api.github.com/users/nadvorny/repos","events_url":"https://api.github.com/users/nadvorny/events{/privacy}","received_events_url":"https://api.github.com/users/nadvorny/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-01-18T22:30:39Z","updated_at":"2015-01-19T16:19:41Z","closed_at":null,"body":"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.\r\n\r\nLifting 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.\r\n\r\nIdeally 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.\r\n\r\n\r\n```javascript\r\nvar when = require('when');\r\nvar node = require('when/node');\r\nvar _ = require('lodash');\r\n\r\n// readFile has the same signature as fs.loadFile\r\nfunction readFile(param1, param2, callback) {\r\n  console.log(Array.prototype.slice.call(arguments));\r\n  callback(null, [param1, param2]);\r\n}\r\n\r\nvar foo = node.lift(readFile);\r\n\r\nvar bar = function (fileName, index) {\r\n  return node.lift(readFile)(fileName);\r\n};\r\n\r\nwhen.map(['1', '2'], bar).done(); // works\r\nwhen.map(['3', '4'], foo).done(); // does not work\r\n```\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/cujojs/when/issues/comments/70519908","html_url":"https://github.com/cujojs/when/issues/420#issuecomment-70519908","issue_url":"https://api.github.com/repos/cujojs/when/issues/420","id":70519908,"user":{"login":"briancavalier","id":90518,"avatar_url":"https://avatars.githubusercontent.com/u/90518?v=3","gravatar_id":"","url":"https://api.github.com/users/briancavalier","html_url":"https://github.com/briancavalier","followers_url":"https://api.github.com/users/briancavalier/followers","following_url":"https://api.github.com/users/briancavalier/following{/other_user}","gists_url":"https://api.github.com/users/briancavalier/gists{/gist_id}","starred_url":"https://api.github.com/users/briancavalier/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/briancavalier/subscriptions","organizations_url":"https://api.github.com/users/briancavalier/orgs","repos_url":"https://api.github.com/users/briancavalier/repos","events_url":"https://api.github.com/users/briancavalier/events{/privacy}","received_events_url":"https://api.github.com/users/briancavalier/received_events","type":"User","site_admin":false},"created_at":"2015-01-19T16:19:41Z","updated_at":"2015-01-19T16:19:41Z","body":"Hey @nadvorny, yeah, this is an interesting issue.  Originally, `when.map` didn't pass the index.  Users felt it was important to match that particular behavior of `Array.prototype.map`, which is a very reasonable expectation, so we added it.\r\n\r\nI like your idea of a `lift` variant that supports specifying a max arity.  Currently, we can't merge that functionality directly into `lift`, since it allows partialing (e.g. `lift(readFile, 'filename')` creates a lifted and partially applied function).  However, that partialing is deprecated and will be removed in 4.0, so in 4.0 we could potentially allow an optional arity parameter.\r\n\r\nBefore 4.0, one option might be to add `liftArity` or `liftn` or somesuch that has a required arity parameter.  Then, when 4.0 lands we could either: 1) add the optional parameter to `lift`, and  deprecate `liftArity`, or 2) keep both to avoid optional parameters (lately, I don't like optional params).\r\n\r\nAny thoughts on that?  Other ideas?\r\n\r\nWould like to get @unscriptable's thoughts as well.\r\n\r\n"}}