{-# language NoImplicitPrelude #-}
{-# options_haddock prune, hide #-}
-- |Prelude, Internal

module Helic.Prelude (
  module Data.Aeson,
  module Data.Aeson.TH,
  module Data.Default,
  module Data.Either.Combinators,
  module Data.Foldable,
  module Data.Kind,
  module Exon,
  module GHC.Err,
  module GHC.TypeLits,
  module Helic.Prelude,
  module Helic.Prelude.Debug,
  module Polysemy,
  module Polysemy.Async,
  module Polysemy.AtomicState,
  module Polysemy.Conc,
  module Polysemy.Error,
  module Polysemy.Internal.Tactics,
  module Polysemy.Reader,
  module Polysemy.Resource,
  module Polysemy.State,
  module Relude,
) where

import Control.Exception (try)
import qualified Data.Aeson as Aeson
import Data.Aeson (FromJSON (parseJSON), SumEncoding (UntaggedValue), ToJSON (toJSON), Value, camelTo2)
import Data.Aeson.TH (deriveFromJSON, deriveJSON)
import Data.Default (Default (def))
import Data.Either.Combinators (mapLeft)
import Data.Foldable (foldl, traverse_)
import Data.Kind (Type)
import Exon (exon)
import GHC.Err (undefined)
import GHC.TypeLits (Symbol)
import qualified Language.Haskell.TH.Syntax as TH
import Polysemy (
  Effect,
  EffectRow,
  Embed,
  Final,
  InterpreterFor,
  InterpretersFor,
  Member,
  Members,
  Sem,
  WithTactics,
  bindT,
  embed,
  embedToFinal,
  interpret,
  interpretH,
  makeSem,
  pureT,
  raise,
  raise2Under,
  raise3Under,
  raiseUnder,
  raiseUnder2,
  raiseUnder3,
  reinterpret,
  runFinal,
  runT,
  )
import Polysemy.Async (Async, async, asyncToIOFinal, await, sequenceConcurrently)
import Polysemy.AtomicState (AtomicState, atomicGet, atomicGets, atomicModify', atomicPut, runAtomicStateTVar)
import Polysemy.Conc (Race)
import Polysemy.Error (Error, fromEither, fromExceptionVia, mapError, note, runError, throw)
import Polysemy.Internal.CustomErrors (FirstOrder)
import Polysemy.Internal.Kind (Append)
import Polysemy.Internal.Tactics (liftT)
import Polysemy.Reader (Reader, ask, asks, runReader)
import Polysemy.Resource (Resource, resourceToIOFinal, runResource)
import Polysemy.State (State, evalState, get, gets, modify, modify', put, runState)
import Relude hiding (
  Reader,
  State,
  Type,
  ask,
  asks,
  evalState,
  filterM,
  get,
  gets,
  hoistEither,
  modify,
  modify',
  put,
  readFile,
  runReader,
  runState,
  state,
  trace,
  traceShow,
  undefined,
  )

import Helic.Prelude.Debug (dbg, dbgs, dbgsWith, dbgs_, tr, trs, trs')

unit ::
  Applicative f =>
  f ()
unit :: f ()
unit =
  () -> f ()
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
{-# inline unit #-}

tryAny ::
  Member (Embed IO) r =>
  IO a ->
  Sem r (Either Text a)
tryAny :: IO a -> Sem r (Either Text a)
tryAny =
  IO (Either Text a) -> Sem r (Either Text a)
forall (m :: * -> *) (r :: EffectRow) a.
Member (Embed m) r =>
m a -> Sem r a
embed (IO (Either Text a) -> Sem r (Either Text a))
-> (IO a -> IO (Either Text a)) -> IO a -> Sem r (Either Text a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Either SomeException a -> Either Text a)
-> IO (Either SomeException a) -> IO (Either Text a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((SomeException -> Text) -> Either SomeException a -> Either Text a
forall a c b. (a -> c) -> Either a b -> Either c b
mapLeft SomeException -> Text
forall b a. (Show a, IsString b) => a -> b
show) (IO (Either SomeException a) -> IO (Either Text a))
-> (IO a -> IO (Either SomeException a))
-> IO a
-> IO (Either Text a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a.
Exception SomeException =>
IO a -> IO (Either SomeException a)
forall e a. Exception e => IO a -> IO (Either e a)
try @SomeException
{-# inline tryAny #-}

catchAny ::
  Member (Embed IO) r =>
  IO a ->
  (Text -> Sem r a) ->
  Sem r a
catchAny :: IO a -> (Text -> Sem r a) -> Sem r a
catchAny IO a
ma Text -> Sem r a
handle =
  (Text -> Sem r a) -> (a -> Sem r a) -> Either Text a -> Sem r a
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either Text -> Sem r a
handle a -> Sem r a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either Text a -> Sem r a) -> Sem r (Either Text a) -> Sem r a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< IO a -> Sem r (Either Text a)
forall (r :: EffectRow) a.
Member (Embed IO) r =>
IO a -> Sem r (Either Text a)
tryAny IO a
ma
{-# inline catchAny #-}

basicOptions :: Aeson.Options
basicOptions :: Options
basicOptions =
  Options
Aeson.defaultOptions {
    fieldLabelModifier :: String -> String
Aeson.fieldLabelModifier = (Char -> Bool) -> String -> String
forall a. (a -> Bool) -> [a] -> [a]
dropWhile (Char
'_' Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
==)
  }

jsonOptions :: Aeson.Options
jsonOptions :: Options
jsonOptions =
  Options
basicOptions {
    unwrapUnaryRecords :: Bool
Aeson.unwrapUnaryRecords = Bool
True
  }

untaggedOptions :: Aeson.Options
untaggedOptions :: Options
untaggedOptions =
  Options
jsonOptions {
    sumEncoding :: SumEncoding
Aeson.sumEncoding = SumEncoding
UntaggedValue
  }

defaultJson :: TH.Name -> TH.Q [TH.Dec]
defaultJson :: Name -> Q [Dec]
defaultJson =
  Options -> Name -> Q [Dec]
deriveJSON Options
jsonOptions

lowerMinusJson :: TH.Name -> TH.Q [TH.Dec]
lowerMinusJson :: Name -> Q [Dec]
lowerMinusJson =
  Options -> Name -> Q [Dec]
deriveJSON Options
jsonOptions {
    constructorTagModifier :: String -> String
Aeson.constructorTagModifier = Char -> String -> String
camelTo2 Char
'-'
  }

unaryRecordJson :: TH.Name -> TH.Q [TH.Dec]
unaryRecordJson :: Name -> Q [Dec]
unaryRecordJson =
  Options -> Name -> Q [Dec]
deriveJSON Options
basicOptions

type a ++ b =
  Append a b

traverseLeft ::
  Applicative m =>
  (a -> m b) ->
  Either a b ->
  m b
traverseLeft :: (a -> m b) -> Either a b -> m b
traverseLeft a -> m b
f =
  (a -> m b) -> (b -> m b) -> Either a b -> m b
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either a -> m b
f b -> m b
forall (f :: * -> *) a. Applicative f => a -> f a
pure
{-# inline traverseLeft #-}

interpreting ::
   e r a .
  FirstOrder e "interpret" =>
  Sem (e : r) a ->
  ( r0 x . e (Sem r0) x -> Sem r x) ->
  Sem r a
interpreting :: Sem (e : r) a
-> (forall (r0 :: EffectRow) x. e (Sem r0) x -> Sem r x) -> Sem r a
interpreting Sem (e : r) a
s forall (r0 :: EffectRow) x. e (Sem r0) x -> Sem r x
h =
  (forall (r0 :: EffectRow) x. e (Sem r0) x -> Sem r x)
-> Sem (e : r) a -> Sem r a
forall (e :: Effect) (r :: EffectRow) a.
FirstOrder e "interpret" =>
(forall (rInitial :: EffectRow) x. e (Sem rInitial) x -> Sem r x)
-> Sem (e : r) a -> Sem r a
interpret forall (r0 :: EffectRow) x. e (Sem r0) x -> Sem r x
h Sem (e : r) a
s
{-# inline interpreting #-}

as ::
  Functor m =>
  a ->
  m b ->
  m a
as :: a -> m b -> m a
as =
  a -> m b -> m a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
(<$)
{-# inline as #-}