summaryrefslogtreecommitdiff
path: root/taskflow/utils
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@yahoo-inc.com>2015-09-04 13:14:25 -0700
committerJoshua Harlow <harlowja@gmail.com>2015-10-01 22:38:30 -0700
commit79d25e69e8300db5debdfd717ffd80f91c246c10 (patch)
tree134e9764a021dc190a1b158fb27f222d9304908e /taskflow/utils
parentba4704cd18ab6d799a2de59bdf0feab9b5430a30 (diff)
downloadtaskflow-79d25e69e8300db5debdfd717ffd80f91c246c10.tar.gz
Simplify flow action engine compilation1.22.0
Instead of the added complexity of discarding flow nodes we can simplify the compilation process by just retaining them and jumping over them in further iteration and graph and tree runtime usage. This change moves toward a model that does just this, which makes it also easier to in the future use the newly added flow graph nodes to do meaningful things (like use them as a point to change which flow_detail is used). Change-Id: Icb1695f4b995a0392f940837514774768f222db4
Diffstat (limited to 'taskflow/utils')
-rw-r--r--taskflow/utils/iter_utils.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/taskflow/utils/iter_utils.py b/taskflow/utils/iter_utils.py
index 68810e8..a96e9cf 100644
--- a/taskflow/utils/iter_utils.py
+++ b/taskflow/utils/iter_utils.py
@@ -16,12 +16,25 @@
# License for the specific language governing permissions and limitations
# under the License.
+import itertools
+
def count(it):
"""Returns how many values in the iterator (depletes the iterator)."""
return sum(1 for _value in it)
+def unique_seen(it, *its):
+ """Yields unique values from iterator(s) (and retains order)."""
+ seen = set()
+ for value in itertools.chain(it, *its):
+ if value in seen:
+ continue
+ else:
+ yield value
+ seen.add(value)
+
+
def find_first_match(it, matcher, not_found_value=None):
"""Searches iterator for first value that matcher callback returns true."""
for value in it: