diff options
Diffstat (limited to 'src/Chelleport/Utils.hs')
| -rw-r--r-- | src/Chelleport/Utils.hs | 8 |
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) |
