summaryrefslogtreecommitdiff
path: root/OptionalUtils.py
diff options
context:
space:
mode:
authorJoel Kronqvist <joel.kronqvist@iki.fi>2025-11-03 23:10:04 +0200
committerJoel Kronqvist <joel.kronqvist@iki.fi>2025-11-03 23:10:04 +0200
commitd1c404fe8eac3c743004a9a48a683e9361c8f7b3 (patch)
treef5df16492fd5cfc3a2915c678306b53c212edb5e /OptionalUtils.py
parentef6abc27cec35e32acef66c5077ffcc6bedde983 (diff)
downloadSnakePuzzle-d1c404fe8eac3c743004a9a48a683e9361c8f7b3.tar.gz
SnakePuzzle-d1c404fe8eac3c743004a9a48a683e9361c8f7b3.zip
fix: added typing
Diffstat (limited to 'OptionalUtils.py')
-rw-r--r--OptionalUtils.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/OptionalUtils.py b/OptionalUtils.py
new file mode 100644
index 0000000..51828bb
--- /dev/null
+++ b/OptionalUtils.py
@@ -0,0 +1,19 @@
+
+from typing import Optional, TypeVar, Callable
+
+
+
+T = TypeVar('T')
+def exists(opt: Optional[T], cond: Callable[[T], bool]) -> bool:
+ match opt:
+ case None:
+ return False
+ case _:
+ return cond(opt)
+
+def foreach(opt: Optional[T], call: Callable[[T], None]) -> None:
+ match opt:
+ case None:
+ return None
+ case _:
+ return call(opt)