diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-11-22 00:05:41 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-11-22 00:05:41 +0000 |
commit | ed41d863810fd62cfb25895e52bfab554e983d8a (patch) | |
tree | ff4f2948d51ace255426885412990bc9489474cb /lib/dicts.bzl | |
parent | f8aadd2ad5a51ac3187333bf589a754c5347d447 (diff) | |
parent | 6b103c40d8113f001475d5e13672922ef2aa0e5a (diff) | |
download | bazel-skylib-ed41d863810fd62cfb25895e52bfab554e983d8a.tar.gz |
Snap for 11130229 from 6b103c40d8113f001475d5e13672922ef2aa0e5a to 24Q1-releaseandroid-14.0.0_r37android-14.0.0_r36android-14.0.0_r35android-14.0.0_r34android-14.0.0_r33android-14.0.0_r32android-14.0.0_r31android-14.0.0_r30android-14.0.0_r29android14-qpr2-s5-releaseandroid14-qpr2-s4-releaseandroid14-qpr2-s3-releaseandroid14-qpr2-s2-releaseandroid14-qpr2-s1-releaseandroid14-qpr2-release
Change-Id: Ie9fcd1b8874f5b9860d47b589d7125896b5aeb72
Diffstat (limited to 'lib/dicts.bzl')
-rw-r--r-- | lib/dicts.bzl | 27 |
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, ) |