diff options
author | Mattias Andrée <maandree@operamail.com> | 2014-03-03 16:20:00 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2014-03-03 16:20:00 +0100 |
commit | 6c6c34d05a75954c07314bc4bdf3f87cb2729ddf (patch) | |
tree | b3d64ad130c4761871a2ea7d5199b78300a9607c /src/util.py | |
parent | add clock (diff) | |
download | xpybar-6c6c34d05a75954c07314bc4bdf3f87cb2729ddf.tar.gz xpybar-6c6c34d05a75954c07314bc4bdf3f87cb2729ddf.tar.bz2 xpybar-6c6c34d05a75954c07314bc4bdf3f87cb2729ddf.tar.xz |
misc
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'src/util.py')
-rw-r--r-- | src/util.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/util.py b/src/util.py index 4698533..6b43e83 100644 --- a/src/util.py +++ b/src/util.py @@ -77,3 +77,20 @@ def spawn_read(*command): if out.endswith('\n'): out = out[:-1] return out + + +def reduce(f, items): + ''' + https://en.wikipedia.org/wiki/Fold_(higher-order_function) + + @param f:(¿E?, ¿E?)→¿E? The function + @param item:itr<¿E?> The input + @return ¿E? The output + ''' + if len(items) < 2: + return items + rc = items[0] + for i in range(1, len(items)): + rc = f(rc, items[i]) + return rc + |