summaryrefslogtreecommitdiff
path: root/lib/spack/llnl/util/lang.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/spack/llnl/util/lang.py')
-rw-r--r--lib/spack/llnl/util/lang.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/spack/llnl/util/lang.py b/lib/spack/llnl/util/lang.py
index 034c3b374d..9a21c5be5c 100644
--- a/lib/spack/llnl/util/lang.py
+++ b/lib/spack/llnl/util/lang.py
@@ -31,6 +31,22 @@ import inspect
# Ignore emacs backups when listing modules
ignore_modules = [r'^\.#', '~$']
+
+def partition_list(elements, predicate):
+ """Partition a list into two lists, the first containing elements
+ for which the predicate evaluates to true, the second containing
+ those for which it is false.
+ """
+ trues = []
+ falses = []
+ for elt in elements:
+ if predicate(elt):
+ trues.append(elt)
+ else:
+ falses.append(elt)
+ return trues, falses
+
+
def caller_locals():
"""This will return the locals of the *parent* of the caller.
This allows a fucntion to insert variables into its caller's