diff options
author | Jan Pokorný <jpokorny@redhat.com> | 2014-01-27 23:04:12 +0100 |
---|---|---|
committer | Jan Pokorný <jpokorny@redhat.com> | 2014-01-27 23:17:41 +0100 |
commit | c33694ac035fe2915c3aa4d39f430ad7d0de753b (patch) | |
tree | a3004a0eef0acff456d6b8a402a79adbb62386ce /utils.py | |
parent | abfb91d87a57970315504508dd094b9f5cdba489 (diff) | |
download | clufter-c33694ac035fe2915c3aa4d39f430ad7d0de753b.tar.gz clufter-c33694ac035fe2915c3aa4d39f430ad7d0de753b.tar.xz clufter-c33694ac035fe2915c3aa4d39f430ad7d0de753b.zip |
command: implement "shapes" match for filter/format chain
Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
Diffstat (limited to 'utils.py')
-rw-r--r-- | utils.py | 17 |
1 files changed, 17 insertions, 0 deletions
@@ -45,6 +45,23 @@ apply_intercalate = apply_aggregation_preserving_depth( i, []) ) +zipped_outlier = type('zipped_outlier', (tuple, ), {}) +# NOTE: automatically shortens the longer counterpart in the pair +# to the length of the bigger one +apply_loose_zip_preserving_depth = \ + lambda a, b: \ + (type(a) if type(a) == type(b) else type(a))( + [apply_loose_zip_preserving_depth(*p) for p in zip(a, b)] + ) if isinstance(a, (tuple, list)) == isinstance(b, (tuple, list)) \ + == True else zipped_outlier([a, b]) +# as previous, but with length checking of some sort +apply_strict_zip_preserving_depth = \ + lambda a, b: \ + (type(a) if type(a) == type(b) else type(a))( + [apply_strict_zip_preserving_depth(*p) for p in zip(a, b)] + ) if isinstance(a, (tuple, list)) == isinstance(b, (tuple, list)) \ + == True and len(a) == len(b) else zipped_outlier([a, b]) + def which(name, *where): """Mimic `which' UNIX utility""" |