{"action":"closed","issue":{"url":"https://api.github.com/repos/tildeio/rsvp.js/issues/395","labels_url":"https://api.github.com/repos/tildeio/rsvp.js/issues/395/labels{/name}","comments_url":"https://api.github.com/repos/tildeio/rsvp.js/issues/395/comments","events_url":"https://api.github.com/repos/tildeio/rsvp.js/issues/395/events","html_url":"https://github.com/tildeio/rsvp.js/issues/395","id":93758738,"number":395,"title":"RSVP filter with promise that resolves to array","user":{"login":"miguelcobain","id":631691,"avatar_url":"https://avatars.githubusercontent.com/u/631691?v=3","gravatar_id":"","url":"https://api.github.com/users/miguelcobain","html_url":"https://github.com/miguelcobain","followers_url":"https://api.github.com/users/miguelcobain/followers","following_url":"https://api.github.com/users/miguelcobain/following{/other_user}","gists_url":"https://api.github.com/users/miguelcobain/gists{/gist_id}","starred_url":"https://api.github.com/users/miguelcobain/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/miguelcobain/subscriptions","organizations_url":"https://api.github.com/users/miguelcobain/orgs","repos_url":"https://api.github.com/users/miguelcobain/repos","events_url":"https://api.github.com/users/miguelcobain/events{/privacy}","received_events_url":"https://api.github.com/users/miguelcobain/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-07-08T10:38:14Z","updated_at":"2015-07-08T15:56:47Z","closed_at":"2015-07-08T15:56:47Z","body":"I think it would be really beneficial if we allow the first argument of `filter` to be a promise, as well as an array of promises.\r\n\r\nFor example, this is possible:\r\n```js\r\nRSVP.filter([1, 2, 3, 4, 5, 6], function(v) {\r\n  return new RSVP.Promise(function(resolve) {\r\n    setTimeout(function() {\r\n      return v > 2 ? resolve(true) : resolve(false);\r\n    }, 1000);\r\n  });\r\n}).then(function(r) {\r\n  console.log(r);\r\n});\r\n//outputs [3, 4, 5, 6]\r\n```\r\n\r\nbut this isn't:\r\n```js\r\nRSVP.filter(Ember.RSVP.resolve([1, 2, 3, 4, 5, 6]), function(v) {\r\n  return new RSVP.Promise(function(resolve) {\r\n    setTimeout(function() {\r\n      return v > 2 ? resolve(true) : resolve(false);\r\n    }, 1000);\r\n  });\r\n}).then(function(r) {\r\n  console.log(r);\r\n});\r\n//outputs \"Error: Array Methods must be provided an Array\"\r\n```\r\n\r\nInstead, I need to map to an array of promises:\r\n```js\r\nRSVP.filter([1, 2, 3, 4, 5, 6].map(function(i){ return RSVP.resolve(i); }),\r\nfunction(v) {\r\n  return new RSVP.Promise(function(resolve) {\r\n    setTimeout(function() {\r\n      return v > 2 ? resolve(true) : resolve(false);\r\n    }, 1000);\r\n  });\r\n}).then(function(r) {\r\n  console.log(r);\r\n});\r\n//outputs [3, 4, 5, 6]\r\n```\r\n\r\nI think the `filter` function should also take a promise that eventually resolves to an array.\r\nThis would prove especially useful to Ember Data users and async relationships. One can just invoke `filter` as `RSVP.filter(model.get('someRelationship'), ...)`. A simple `RSVP.filter(this.store.find(...), ...)` would be nice as well.\r\n\r\nOf course, in my project I could just create a function that normalizes its arguments and then invokes the regular `filter` func, but I thought I should report in to make this available in core RSVP."}}