summaryrefslogtreecommitdiff
path: root/dots_manager/utils.py
diff options
context:
space:
mode:
authorElizabeth <me@liz.coffee>2025-06-02 15:54:32 -0700
committerElizabeth <me@liz.coffee>2025-06-02 15:54:32 -0700
commit03646d1e891271339ca256fadd15eaa8ac678911 (patch)
tree5df23a874fa1ae5c62dad318d9098225852f2137 /dots_manager/utils.py
parentd098e94ad102da9d018acca72ca5a5c554d25a01 (diff)
downloaddotfiles-03646d1e891271339ca256fadd15eaa8ac678911.tar.gz
dotfiles-03646d1e891271339ca256fadd15eaa8ac678911.zip
Make it a python package
Diffstat (limited to 'dots_manager/utils.py')
-rw-r--r--dots_manager/utils.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/dots_manager/utils.py b/dots_manager/utils.py
new file mode 100644
index 0000000..e8210cc
--- /dev/null
+++ b/dots_manager/utils.py
@@ -0,0 +1,25 @@
+from typing import Callable, Optional, TypeVar, Tuple, ParamSpec, Dict, Any
+from functools import reduce
+
+P = ParamSpec("P")
+T = TypeVar("T")
+
+
+def is_some(
+ callable: Callable[P, Optional[T]], *args: P.args, **kwargs: P.kwargs
+) -> Tuple[bool, Optional[T]]:
+ result = callable(*args, **kwargs)
+ return result is not None, result
+
+
+def merge_dicts(*dicts: Dict[str, Any]) -> Dict[str, Any]:
+ def merge(a: Dict[str, Any], b: Dict[str, Any]) -> Dict[str, Any]:
+ out = dict(a)
+ for k, v in b.items():
+ if k in out and isinstance(out[k], dict) and isinstance(v, dict):
+ out[k] = merge(out[k], v)
+ else:
+ out[k] = v
+ return out
+
+ return reduce(merge, dicts, {})