Skip to content
Snippets Groups Projects
Commit a8707a1d authored by Piotr Maślanka's avatar Piotr Maślanka
Browse files

tests

parent 2175af30
No related branches found
No related tags found
No related merge requests found
...@@ -153,21 +153,15 @@ class Heap(object): ...@@ -153,21 +153,15 @@ class Heap(object):
""" """
return heapq.heappop(self.heap) return heapq.heappop(self.heap)
# TODO needs tests
@typed(object, (Callable, None), (Callable, None)) @typed(object, (Callable, None), (Callable, None))
def filtermap(self, filter_fun=None, map_fun=None): def filtermap(self, filter_fun=None, map_fun=None):
""" """
Get only items that return True when condition(item) is True. Apply a transform: item' = item(condition) on Get only items that return True when condition(item) is True. Apply a transform: item' = item(condition) on
the rest. Maintain heap invariant. the rest. Maintain heap invariant.
""" """
if self.filter_fun: self.heap = filter(filter_fun, self.heap) if filter_fun else self.heap
self.heap = filter(filter_fun, self.heap) self.heap = map(map_fun, self.heap) if map_fun else self.heap
if self.map_fun: self.heap = list(self.heap) if not isinstance(self.heap, list) else self.heap
self.heap = map(map_fun, self.heap)
if not isinstance(self.heap, list):
self.heap = list(self.heap)
heapq.heapify(self.heap) heapq.heapify(self.heap)
@typed(returns=bool) @typed(returns=bool)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment