Title: Run _.filter and _.reject as a single operation, like Haskell's Data.List.Partition
Tags: underscore.js;filtering;lodash
Question: I would like to partition values in a JavaScript array into two separate arrays based on whether a predicate returns true or false for the value. This can be easily done as two operations using Underscore or Lo-Dash:
var values = [1, 2, 3, 4];
var even = function (num) { return num % 2 === 0; };
var evens = _.filter(values, even);
var odds = _.reject(values, even);
This will run the predicate on each value twice, which is alright here but could be problematic if values were replaced with a larger set of data, and if even were replaced with a more computationally expensive predicate.
I looked through the documentation for Lo-Dash, but could not see anything that would do this in a single operation. I can manually write such a function, but it seems a strange omission. Is there a function like this that I am missing?

Here is the accepted answer: Underscore has _.partition:
partition _.partition(array, predicate)
Split array into two arrays: one whose elements all satisfy predicate and one whose elements all do not satisfy predicate.
but it seems that Lo-Dash doesn't (yet) have it. You could use groupBy instead:
var partition = _.groupBy(values, function(num) { return num % 2 === 0 });
and then pull the two pieces out of the partition object yourself; that's still two steps I suppose but only pass through values. This will, of course, stringify the boolean keys but that shouldn't be a problem.
Comment for this answer: `_.partition` is fairly new in Underscore, the [Change Log](http://underscorejs.org/#changelog) says it came in with 1.6.0 in February so maybe Lo-Dash hasn't gotten around to matching that part of the Underscore interface yet. I like the idea of submitting a patch.
Comment for this answer: So the lesson is to check underscore docs first, rather than believe that lodash has everything from underscore. I guess I should look at submitting a patch to lodash for this.
Comment for this answer: Looks like partition is on its way into Lo-Dash, according to https://github.com/lodash/lodash/issues/177 (and they mention the same workaround of using `_.groupBy`),


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2014:00:09/23/14', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<underscore.js><filtering><lodash>', 'Title': "Run _.filter and _.reject as a single operation, like Haskell's Data.List.Partition", 'ViewCount': 654, 'id': 25987474, 'user_AboutMe': '<p>I have loved coding from the moment I discovered it! I love to learn, so I try to become familiar with as many technologies as possible. The major benefits I reap from this are that I tend not to be overly constrained when selecting the right tool for the job, I can usually provide some insight to my peers when they need help, and I gain a stronger appreciation for the common principles underlying various technologies.</p>\n\n<p>I work professionally in web development using all the usual tools. I work across the full stack, but lean towards the frontend and user experience side.</p>\n\n<p>When I can find some spare time, I dabble in game development.</p>\n', 'user_AccountId': 113040.0, 'user_DisplayName': 'David Mason', 'user_Reputation': 2842.0, 'user_Views': 398.0, 'user_id': 297938.0}}