Tweak functor used to find flatteners/storage routines

Make both of these finding functions use similar routines
that the utility module now provides since the logic that
both use can be shared.

Change-Id: Ib941b99945d42f5c0d791e9b2a0696d0e62a2388
This commit is contained in:
Joshua Harlow
2015-03-02 18:49:17 -08:00
parent d4f02f6fea
commit b598897d15
5 changed files with 34 additions and 36 deletions

View File

@@ -87,6 +87,18 @@ def find_monotonic(allow_time_time=False):
return None
def match_type_handler(item, type_handlers):
"""Matches a given items type using the given match types + handlers.
Returns the handler if a type match occurs, otherwise none.
"""
for (match_types, handler_func) in type_handlers:
if isinstance(item, match_types):
return handler_func
else:
return None
def countdown_iter(start_at, decr=1):
"""Generator that decrements after each generation until <= zero.