aboutsummaryrefslogtreecommitdiff
path: root/src/Chelleport/Utils.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Chelleport/Utils.hs')
-rw-r--r--src/Chelleport/Utils.hs12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/Chelleport/Utils.hs b/src/Chelleport/Utils.hs
index 3f0dd73..4367c4f 100644
--- a/src/Chelleport/Utils.hs
+++ b/src/Chelleport/Utils.hs
@@ -37,15 +37,21 @@ benchmark msg m = do
pure result
itemAt :: [a] -> Int -> Maybe a
-itemAt [] _ = Nothing
itemAt (x : _) 0 = Just x
itemAt (_ : xs) i = itemAt xs (i - 1)
+itemAt _ _ = Nothing
clamp :: (Integral a) => (a, a) -> a -> a
clamp (low, high) n = max low (min high n)
-(<&&>) :: [a -> Bool] -> a -> Bool
-(<&&>) preds ev = all (\p -> p ev) preds
+cycleInRange :: (Integral a) => (a, a) -> a -> a
+cycleInRange (low, high) n
+ | n < low = high
+ | high <= low = low
+ | otherwise = low + ((n - low) `mod` (high - low + 1))
+
+(<&&>) :: (a -> Bool) -> (a -> Bool) -> a -> Bool
+(<&&>) p1 p2 x = p1 x && p2 x
(<||>) :: (a -> Bool) -> (a -> Bool) -> a -> Bool
(<||>) p1 p2 x = p1 x || p2 x