summaryrefslogtreecommitdiff
path: root/asciifarmclient/utils.py
diff options
context:
space:
mode:
authortroido <troido@protonmail.com>2020-03-06 11:48:33 +0100
committertroido <troido@protonmail.com>2020-03-06 11:48:33 +0100
commit09cf076ab48d79f6c4bbcd6d1f606e1747d5da6b (patch)
treebcc8ea0cd149d97d25d19c1be7e78d267e214049 /asciifarmclient/utils.py
parent77d1959b873e4f75bcc9878a6bdcc4707465f632 (diff)
moved utils into main code directory
Diffstat (limited to 'asciifarmclient/utils.py')
-rw-r--r--asciifarmclient/utils.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/asciifarmclient/utils.py b/asciifarmclient/utils.py
new file mode 100644
index 0000000..471dd89
--- /dev/null
+++ b/asciifarmclient/utils.py
@@ -0,0 +1,12 @@
+
+import os
+
+def clamp(val, lower, upper):
+ """ val if it's between lower and upper, else the closest of the two"""
+ return max(min(val, upper), lower)
+
+def get(collection, i, default=None):
+ """ Get an element in an indexed collection, or the default in case the index is out of bounds """
+ if i < 0 or i >= len(collection):
+ return default
+ return collection[i]