aboutsummaryrefslogtreecommitdiffstats
path: root/src/util.py
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-03-03 16:20:00 +0100
committerMattias Andrée <maandree@operamail.com>2014-03-03 16:20:00 +0100
commit6c6c34d05a75954c07314bc4bdf3f87cb2729ddf (patch)
treeb3d64ad130c4761871a2ea7d5199b78300a9607c /src/util.py
parentadd clock (diff)
downloadxpybar-6c6c34d05a75954c07314bc4bdf3f87cb2729ddf.tar.gz
xpybar-6c6c34d05a75954c07314bc4bdf3f87cb2729ddf.tar.bz2
xpybar-6c6c34d05a75954c07314bc4bdf3f87cb2729ddf.tar.xz
misc
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r--src/util.py17
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
+