module Prelude
  ( module Exports,
    -- | Custom prelude functions
    parseInt,
    headMay,
  )
where

import Control.Monad.Trans.Resource as Exports
  ( ResourceT,
    liftResourceT,
    runResourceT,
  )
import qualified Data.Text.Read as TR
-- Text formatting
import Formatting as Exports (format, sformat, (%))
import Formatting.ShortFormatters as Exports (d, sh, st, t)
import Network.HTTP.Types as Exports
import Network.Wai as Exports
import Relude as Exports hiding (get, put)
import UnliftIO.Exception as Exports (throwIO)

parseInt :: Integral a => Text -> Maybe a
parseInt :: Text -> Maybe a
parseInt Text
t' = (String -> Maybe a)
-> ((a, Text) -> Maybe a) -> Either String (a, Text) -> Maybe a
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (Maybe a -> String -> Maybe a
forall a b. a -> b -> a
const Maybe a
forall a. Maybe a
Nothing) (a -> Maybe a
forall a. a -> Maybe a
Just (a -> Maybe a) -> ((a, Text) -> a) -> (a, Text) -> Maybe a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a, Text) -> a
forall a b. (a, b) -> a
fst) (Reader a
forall a. Integral a => Reader a
TR.decimal Text
t')

headMay :: [a] -> Maybe a
headMay :: [a] -> Maybe a
headMay [] = Maybe a
forall a. Maybe a
Nothing
headMay (a
a : [a]
_) = a -> Maybe a
forall a. a -> Maybe a
Just a
a