aboutsummaryrefslogtreecommitdiff
path: root/src/Chelleport/Utils.hs
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2024-12-25 00:17:52 +0530
committerAkshay Nair <phenax5@gmail.com>2024-12-25 00:32:39 +0530
commit82d612b7c37b432bc4abd8e158d6fe076d391ddc (patch)
treeef61b3910e5a54fc0ff581e36392e27150ccf470 /src/Chelleport/Utils.hs
parent459488a2e777380fcb65e3b4dd355fe525ff77ca (diff)
downloadchelleport-82d612b7c37b432bc4abd8e158d6fe076d391ddc.tar.gz
chelleport-82d612b7c37b432bc4abd8e158d6fe076d391ddc.zip
Add <c-n> and <c-p> to walk through matches
Diffstat (limited to 'src/Chelleport/Utils.hs')
-rw-r--r--src/Chelleport/Utils.hs8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/Chelleport/Utils.hs b/src/Chelleport/Utils.hs
index c15a3e8..9423e5d 100644
--- a/src/Chelleport/Utils.hs
+++ b/src/Chelleport/Utils.hs
@@ -35,3 +35,11 @@ benchmark msg m = do
end <- systemNanoseconds <$> liftIO getSystemTime
Debug.traceM $ msg ++ " (ms): " ++ show (fromIntegral (end - start) / 1_000_000.0 :: Double)
pure result
+
+itemAt :: [a] -> Int -> Maybe a
+itemAt [] _ = Nothing
+itemAt (x : _) 0 = Just x
+itemAt (_ : xs) i = itemAt xs (i - 1)
+
+clamp :: (Integral a) => (a, a) -> a -> a
+clamp (low, high) n = max low (min high n)