kino/src/Kino/Misc.hs

33 lines
835 B
Haskell

{-|
Module : Kino.Misc
Description : Contains miscellaneous helper functions which do not fit elsewhere
Contains miscellaneous helper functions which do not fit elsewhere
-}
module Kino.Misc where
import Lens.Micro
import Kino.Types
infixl 3 !?
-- | Safe version of (!!)
(!?) :: [a] -> Int -> Maybe a
[] !? _ = Nothing
(x:_) !? 0 = Just x
(_:xs) !? n = xs !? (n-1)
infixl 0 $>
-- | Backwards function application
($>) :: a -> (a -> b) -> b
x $> f = f x
-- | Given a String, modify our state so that string
-- is displayed as a message, alternatively forcing
-- an exit after the message is aknowledged.
displayMessage :: AppS -> Bool -> String -> AppS
displayMessage s fatal msg = s & appMode .~ Message
& appMessage ?~ msg
& appContinue .~ not fatal