Add groupByAdjacent operator to folly::gen
Summary: I find myself wanting something like this pretty often, so I tried my hand at adding it myself. The `groupByAdjacent` operator creates groups bounded wherever the selector changes. It's especially useful for processing sources that've already been sorted on the selector, such as from a database query. Given the following source sequence with keys `A` and `B`: ``` [A1, A2, A3, B1, B2, B3, A4, A5, B4, B5] ``` a regular `groupBy` would return something like: ``` [A:[A1, A2, A3, A4, A5], B:[B1, B2, B3, B4, B5]] ``` while this `groupByAdjacent` would return: ``` [A:[A1, A2, A3], B:[B1, B2, B3], A:[A4, A5], B:[B4, B5]] ``` Given a source where the items are presorted by selector, `groupByAdjacent` should behave identically to `groupBy`, except that `groupByAdjacent` supports infinite sources since it doesn't need to collect the entire source in memory before creating any output. Reviewed By: yfeldblum Differential Revision: D9475326 fbshipit-source-id: 1c8db3abadce5e68394e5fa38bf4bee0b413a03f
Showing
Please register or sign in to comment