{-# LANGUAGE CPP #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
module Preamble.Prelude
( module Exports
, maybe'
, either'
, maybe_
, eitherThrowIO
, eitherThrowIO'
, maybeThrowIO
, maybeThrowIO'
, boolThrowIO
, textFromString
, textShow
, stringShow
, (-/-)
, (-|-)
, (-.-)
, (-:-)
, (=.)
) where
import BasicPrelude as Exports hiding (bool)
#if MIN_VERSION_basic_prelude(0,7,0)
import Control.Exception.Lifted as Exports hiding (ioError)
#endif
import Control.Lens as Exports hiding (uncons, (.=), (<.>))
import Data.Bool as Exports
import Data.Text
import Safe as Exports (headMay, initMay, tailMay)
maybe' :: Maybe a -> b -> (a -> b) -> b
maybe' m b a = maybe b a m
either' :: Either a b -> (a -> c) -> (b -> c) -> c
either' e b a = either b a e
maybe_ :: Applicative f => Maybe a -> (a -> f ()) -> f ()
maybe_ = flip $ maybe $ pure ()
eitherThrowIO :: (MonadIO m, Exception e) => Either e a -> m a
eitherThrowIO = either (liftIO . throwIO) pure
eitherThrowIO' :: MonadIO m => Either String a -> m a
eitherThrowIO' = either (liftIO . throwIO . userError) pure
maybeThrowIO :: (MonadIO m, Exception e) => e -> Maybe a -> m a
maybeThrowIO e = maybe (liftIO $ throwIO e) pure
maybeThrowIO' :: MonadIO m => String -> Maybe a -> m a
maybeThrowIO' s = maybe (liftIO $ throwIO $ userError s) pure
boolThrowIO :: MonadIO m => String -> Bool -> m ()
boolThrowIO = flip unless . liftIO . throwIO . userError
textFromString :: String -> Text
textFromString = pack
textShow :: Show a => a -> Text
textShow =
#if MIN_VERSION_basic_prelude(0,6,1)
textFromString . show
#else
show
#endif
stringShow :: Show a => a -> String
stringShow =
#if MIN_VERSION_basic_prelude(0,6,1)
show
#else
textToString . show
#endif
(-/-) :: (IsString s, Monoid s) => s -> s -> s
(-/-) = (<>) . (<> "/")
(-|-) :: (IsString s, Monoid s) => s -> s -> s
(-|-) = (<>) . (<> "|")
(-.-) :: (IsString s, Monoid s) => s -> s -> s
(-.-) = (<>) . (<> ".")
(-:-) :: (IsString s, Monoid s) => s -> s -> s
(-:-) = (<>) . (<> ":")
(=.) :: a -> b -> (a, b)
(=.) = (,)