aboutsummaryrefslogtreecommitdiff
path: root/lib/dicts.bzl
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-11-22 00:05:41 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-11-22 00:05:41 +0000
commited41d863810fd62cfb25895e52bfab554e983d8a (patch)
treeff4f2948d51ace255426885412990bc9489474cb /lib/dicts.bzl
parentf8aadd2ad5a51ac3187333bf589a754c5347d447 (diff)
parent6b103c40d8113f001475d5e13672922ef2aa0e5a (diff)
downloadbazel-skylib-ed41d863810fd62cfb25895e52bfab554e983d8a.tar.gz
Change-Id: Ie9fcd1b8874f5b9860d47b589d7125896b5aeb72
Diffstat (limited to 'lib/dicts.bzl')
-rw-r--r--lib/dicts.bzl27
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/dicts.bzl b/lib/dicts.bzl
index 3f8e661..5a92aa1 100644
--- a/lib/dicts.bzl
+++ b/lib/dicts.bzl
@@ -38,6 +38,33 @@ def _add(*dictionaries, **kwargs):
result.update(kwargs)
return result
+def _omit(dictionary, keys):
+ """Returns a new `dict` that has all the entries of `dictionary` with keys not in `keys`.
+
+ Args:
+ dictionary: A `dict`.
+ keys: A sequence.
+
+ Returns:
+ A new `dict` that has all the entries of `dictionary` with keys not in `keys`.
+ """
+ keys_set = {k: None for k in keys}
+ return {k: dictionary[k] for k in dictionary if k not in keys_set}
+
+def _pick(dictionary, keys):
+ """Returns a new `dict` that has all the entries of `dictionary` with keys in `keys`.
+
+ Args:
+ dictionary: A `dict`.
+ keys: A sequence.
+
+ Returns:
+ A new `dict` that has all the entries of `dictionary` with keys in `keys`.
+ """
+ return {k: dictionary[k] for k in keys if k in dictionary}
+
dicts = struct(
add = _add,
+ omit = _omit,
+ pick = _pick,
)