2018-06-27 16:11:32 +03:00
|
|
|
module Hasura.Prelude
|
|
|
|
( module M
|
2019-02-22 15:25:36 +03:00
|
|
|
, onNothing
|
|
|
|
, onJust
|
|
|
|
, onLeft
|
2019-07-22 15:47:13 +03:00
|
|
|
, choice
|
2019-07-11 08:37:06 +03:00
|
|
|
, bsToTxt
|
|
|
|
, txtToBs
|
2018-06-27 16:11:32 +03:00
|
|
|
) where
|
|
|
|
|
2019-07-22 15:47:13 +03:00
|
|
|
import Control.Applicative as M (Alternative (..))
|
2019-04-09 19:11:06 +03:00
|
|
|
import Control.Monad as M (void, when)
|
|
|
|
import Control.Monad.Base as M
|
|
|
|
import Control.Monad.Except as M
|
|
|
|
import Control.Monad.Fail as M (MonadFail)
|
|
|
|
import Control.Monad.Identity as M
|
|
|
|
import Control.Monad.Reader as M
|
|
|
|
import Control.Monad.State.Strict as M
|
|
|
|
import Data.Bool as M (bool)
|
2019-08-17 00:35:22 +03:00
|
|
|
import Data.Data as M (Data (..))
|
2019-04-09 19:11:06 +03:00
|
|
|
import Data.Either as M (lefts, partitionEithers,
|
|
|
|
rights)
|
2019-07-22 15:47:13 +03:00
|
|
|
import Data.Foldable as M (foldrM, for_, toList,
|
|
|
|
traverse_)
|
|
|
|
import Data.Function as M (on, (&))
|
2019-07-15 11:52:45 +03:00
|
|
|
import Data.Functor as M (($>), (<&>))
|
2019-04-09 19:11:06 +03:00
|
|
|
import Data.Hashable as M (Hashable)
|
|
|
|
import Data.List as M (find, foldl', group,
|
|
|
|
intercalate, intersect,
|
|
|
|
lookup, sort, sortBy, sortOn,
|
|
|
|
union, unionBy, (\\))
|
|
|
|
import Data.Maybe as M (catMaybes, fromMaybe, isJust,
|
|
|
|
isNothing, listToMaybe,
|
|
|
|
mapMaybe, maybeToList)
|
|
|
|
import Data.Ord as M (comparing)
|
|
|
|
import Data.Semigroup as M (Semigroup (..))
|
|
|
|
import Data.String as M (IsString)
|
|
|
|
import Data.Text as M (Text)
|
2019-07-22 15:47:13 +03:00
|
|
|
import Data.Traversable as M (for)
|
2019-04-09 19:11:06 +03:00
|
|
|
import Data.Word as M (Word64)
|
|
|
|
import GHC.Generics as M (Generic)
|
|
|
|
import Prelude as M hiding (fail, init, lookup)
|
|
|
|
import Text.Read as M (readEither, readMaybe)
|
2019-02-22 15:25:36 +03:00
|
|
|
|
2019-07-11 08:37:06 +03:00
|
|
|
import qualified Data.ByteString as B
|
|
|
|
import qualified Data.Text.Encoding as TE
|
|
|
|
import qualified Data.Text.Encoding.Error as TE
|
|
|
|
|
2019-02-22 15:25:36 +03:00
|
|
|
onNothing :: (Monad m) => Maybe a -> m a -> m a
|
|
|
|
onNothing m act = maybe act return m
|
|
|
|
|
|
|
|
onJust :: (Monad m) => Maybe a -> (a -> m ()) -> m ()
|
|
|
|
onJust m action = maybe (return ()) action m
|
|
|
|
|
|
|
|
onLeft :: (Monad m) => Either e a -> (e -> m a) -> m a
|
|
|
|
onLeft e f = either f return e
|
|
|
|
|
2019-07-22 15:47:13 +03:00
|
|
|
choice :: (Alternative f) => [f a] -> f a
|
|
|
|
choice = foldr (<|>) empty
|
|
|
|
|
2019-07-11 08:37:06 +03:00
|
|
|
bsToTxt :: B.ByteString -> Text
|
|
|
|
bsToTxt = TE.decodeUtf8With TE.lenientDecode
|
2019-02-22 15:25:36 +03:00
|
|
|
|
2019-07-11 08:37:06 +03:00
|
|
|
txtToBs :: Text -> B.ByteString
|
|
|
|
txtToBs = TE.encodeUtf8
|