summaryrefslogtreecommitdiff
path: root/taskflow/utils
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@gmail.com>2015-12-11 08:40:23 -0800
committerJoshua Harlow <harlowja@gmail.com>2016-01-09 22:42:17 -0800
commitf555a35f3081ba492db15d7bda11fbe50f2a8349 (patch)
treefaffe9b329fbceacb07b7668c1e4c62df7cc8db8 /taskflow/utils
parentc6fd876c3ea7aaf8e6a20c8784155838d9cd7c8e (diff)
downloadtaskflow-f555a35f3081ba492db15d7bda11fbe50f2a8349.tar.gz
Fix wrong usage of iter_utils.unique_seen
This wasn't actually using the right data to derive uniqueness, so fix it to actually use the right entry to determine what to skip or what not to skip. Closes-Bug: #1525379 Change-Id: Ic23b6d03877f7714f6a3fb74adac0ba58cd97f0d
Diffstat (limited to 'taskflow/utils')
-rw-r--r--taskflow/utils/iter_utils.py17
1 files changed, 9 insertions, 8 deletions
diff --git a/taskflow/utils/iter_utils.py b/taskflow/utils/iter_utils.py
index 413b36f..959f666 100644
--- a/taskflow/utils/iter_utils.py
+++ b/taskflow/utils/iter_utils.py
@@ -91,7 +91,7 @@ def generate_delays(delay, max_delay, multiplier=2):
return _gen_it()
-def unique_seen(it, *its):
+def unique_seen(its, seen_selector=None):
"""Yields unique values from iterator(s) (and retains order)."""
def _gen_it(all_its):
@@ -99,16 +99,17 @@ def unique_seen(it, *its):
# can happen before generation/iteration... (instead of
# during generation/iteration)
seen = set()
- while all_its:
- it = all_its.popleft()
+ for it in all_its:
for value in it:
- if value not in seen:
+ if seen_selector is not None:
+ maybe_seen_value = seen_selector(value)
+ else:
+ maybe_seen_value = value
+ if maybe_seen_value not in seen:
yield value
- seen.add(value)
+ seen.add(maybe_seen_value)
- all_its = collections.deque([it])
- if its:
- all_its.extend(its)
+ all_its = list(its)
for it in all_its:
if not isinstance(it, collections.Iterable):
raise ValueError("Iterable expected, but '%s' is"