Ejemplo n.º 1
0
	def group_while_core(self,pred,group_op):
		iterable = self.iterable
		groups = HistoricalContext(deque)
		for item in iterable:
			if len(groups.current) == 0 or pred(item,groups.current):
				groups.current.append(item)
			else:
				groups.next.append(item)
				group_op(groups.current)
				yield groups.current
				groups.new_next()
		if not empty(groups.current): yield groups.current
Ejemplo n.º 2
0
	def pcn_iter_core(self):
		"""
			yields triples of (previous,current,next)
			for every item in iterable,
			with None if there is no previous or next
		"""
		iterable = self.iterable
		h = HistoricalContext()
		yielded_anything = False
		for item in iterable:
			h.set_next(item)
			if h.current is not None:
				yield h.pcn_tuple()
				yielded_anything = True
		h.new_next()
		result = h.pcn_tuple()
		(p,c,n) = result
		if c is not None:
			yield result