diff options
Diffstat (limited to 'lib/sqlalchemy/util.py')
-rw-r--r-- | lib/sqlalchemy/util.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/sqlalchemy/util.py b/lib/sqlalchemy/util.py index 54b1afa9f..c2e0dbc45 100644 --- a/lib/sqlalchemy/util.py +++ b/lib/sqlalchemy/util.py @@ -35,6 +35,16 @@ def to_set(x): else: return x +def flatten_iterator(x): + """given an iterator of which further sub-elements may also be iterators, + flatten the sub-elements into a single iterator.""" + for elem in x: + if hasattr(elem, '__iter__'): + for y in flatten_iterator(elem): + yield y + else: + yield elem + def reversed(seq): try: return __builtin__.reversed(seq) |