From 82d612b7c37b432bc4abd8e158d6fe076d391ddc Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Wed, 25 Dec 2024 00:17:52 +0530 Subject: Add and to walk through matches --- src/Chelleport/Utils.hs | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/Chelleport/Utils.hs') 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) -- cgit v1.3.1