def _sort_and_combine(self): values = self._values function = self.combine collector = self._collector extractor = self._extract_keys grouping = defaultdict(list) for value in values: grouping[extractor(value)].append(value) keys = list(grouping.keys()) keys.sort() for key in keys: iterator = Iterator.ListIterator(grouping[key]) base = iterator.next() while iterator.has_next(): base = function(base, iterator.next()) collector.collect(base) self._values = []
def _sort_and_combine(self): values = self._values function = self.combine collector = self._collector extractor = self._extract_keys grouping = defaultdict(list) for value in values: grouping[extractor(value)].append(value) keys = list(grouping.keys()) keys.sort() for key in keys: values = grouping[key] for op in reversed(self._sort_ops): values.sort(key=lambda x: x[op[0]], reverse=op[1] == Order.DESCENDING) result = function(Iterator.ListIterator(values), collector) if result is not None: for res in result: collector.collect(res) self._values = []