{-# OPTIONS_HADDOCK not-home, hide #-}
module IHP.Prelude
( module CorePrelude
, module Data.Text.IO
, module IHP.HaskellSupport
, module GHC.Records
, UUID
, module Data.Default
, tshow
, Proxy (..)
, module Control.Monad
, module Data.List
, head
, headMay
, last
, lastMay
, tail
, tailMay
, init
, initMay
, show
, module Data.String.Conversions
, module Data.Time.Clock
, module Data.Time.Calendar
, module Data.Time.LocalTime
, module Data.Text
, module GHC.OverloadedLabels
, plain
, (++)
, error
, module Data.Data
, module GHC.TypeLits
, module IHP.NameSupport
, module IHP.ModelSupport
, module Data.TMap
, module Data.IORef
, module Data.Time.Format
, null
, module Control.Exception.Safe
, module Control.Monad.Fail
, module Control.Concurrent.Async
, module NeatInterpolation
, module GHC.Stack
, module Data.Kind
, type (~)
, OsPath
, textToOsPath
, osPathToText
)
where

import CorePrelude hiding (putStr, putStrLn, print, error)
import Data.Text.IO (putStr, putStrLn)
import IHP.HaskellSupport
import Data.Default (def, Default (..))
import ClassyPrelude (null)
import Data.UUID (UUID)
import GHC.Records
import qualified Prelude
import qualified Data.Text as Text
import Data.Proxy (Proxy (Proxy))
import Control.Monad (when, unless, mapM, mapM_, forM, forM_, sequence, sequence_, join, forever)
import Data.List hiding (head, last, unwords, unlines, words, lines, isPrefixOf, isSuffixOf, isInfixOf, intercalate, intersperse, (++), splitAt, null, tail, init)
import Data.String.Conversions (ConvertibleStrings (convertString), cs)
import Data.Time.Clock
import Data.Time.Calendar
import Data.Time.LocalTime
import Data.Text (words, unwords, lines, unlines, intersperse, intercalate, toLower, toUpper, isInfixOf, isSuffixOf, isPrefixOf, splitAt)
import qualified "interpolate" Data.String.Interpolate
import GHC.OverloadedLabels
import Data.Data (Data)
import GHC.TypeLits (KnownSymbol, Symbol, symbolVal)
import IHP.NameSupport
import IHP.ModelSupport (ModelContext (..), CanUpdate, NormalizeModel, Id, GetTableName, GetModelName, updateRecord, updateRecordDiscardResult, createRecord, deleteRecord, MetaBag (..))
import Data.TMap (TMap)
import Data.IORef
import Data.Time.Format
import Control.Exception.Safe (throw, throwIO, catch)
import Control.Monad.Fail (fail)
import Control.Concurrent.Async
import NeatInterpolation (trimming)
import GHC.Stack (HasCallStack, CallStack)
import Data.Kind (Type)
import Data.Type.Equality (type (~))
import System.OsPath (OsPath)
import qualified System.OsPath as OsPath
import System.IO.Unsafe (unsafePerformIO)

-- Alias for haskell newcomers :)
a
a ++ :: a -> a -> a
++ a
b = a
a a -> a -> a
forall a. Semigroup a => a -> a -> a
<> a
b

tshow :: Show a => a -> Text
tshow :: forall a. Show a => a -> Text
tshow a
value = FilePath -> Text
Text.pack (a -> FilePath
forall a. Show a => a -> FilePath
Prelude.show a
value)

show :: Show a => a -> Text
show :: forall a. Show a => a -> Text
show = a -> Text
forall a. Show a => a -> Text
tshow

error :: Text -> a
error :: forall a. Text -> a
error Text
message = FilePath -> a
forall a. HasCallStack => FilePath -> a
Prelude.error (Text -> FilePath
Text.unpack Text
message)

head :: [a] -> Maybe a
head :: forall a. [a] -> Maybe a
head [] = Maybe a
forall a. Maybe a
Nothing
head (a
firstItem:[a]
rest) = a -> Maybe a
forall a. a -> Maybe a
Just a
firstItem

headMay :: [a] -> Maybe a
headMay :: forall a. [a] -> Maybe a
headMay = [a] -> Maybe a
forall a. [a] -> Maybe a
head

last :: [a] -> Maybe a
last :: forall a. [a] -> Maybe a
last [] = Maybe a
forall a. Maybe a
Nothing
last [a
item] = a -> Maybe a
forall a. a -> Maybe a
Just a
item
last (a
_:[a]
rest) = [a] -> Maybe a
forall a. [a] -> Maybe a
last [a]
rest

lastMay :: [a] -> Maybe a
lastMay :: forall a. [a] -> Maybe a
lastMay = [a] -> Maybe a
forall a. [a] -> Maybe a
last

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

tailMay :: [a] -> Maybe [a]
tailMay :: forall a. [a] -> Maybe [a]
tailMay = [a] -> Maybe [a]
forall a. [a] -> Maybe [a]
tail

init :: [a] -> Maybe [a]
init :: forall a. [a] -> Maybe [a]
init [a]
list = ([a], a) -> [a]
forall a b. (a, b) -> a
fst (([a], a) -> [a]) -> Maybe ([a], a) -> Maybe [a]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ([a] -> Maybe ([a], a)
forall a. [a] -> Maybe ([a], a)
unsnoc [a]
list)

initMay :: [a] -> Maybe [a]
initMay :: forall a. [a] -> Maybe [a]
initMay = [a] -> Maybe [a]
forall a. [a] -> Maybe [a]
init

plain :: QuasiQuoter
plain = QuasiQuoter
Data.String.Interpolate.i

-- | Pure conversion from Text to OsPath using UTF-8 encoding.
-- On POSIX (where IHP runs), this is safe for all valid Text values.
textToOsPath :: Text -> OsPath
textToOsPath :: Text -> OsPath
textToOsPath Text
text = IO OsPath -> OsPath
forall a. IO a -> a
unsafePerformIO (FilePath -> IO OsPath
forall (m :: * -> *). MonadThrow m => FilePath -> m OsPath
OsPath.encodeUtf (Text -> FilePath
forall a b. ConvertibleStrings a b => a -> b
cs Text
text))
{-# NOINLINE textToOsPath #-}

-- | Pure conversion from OsPath to Text using UTF-8 decoding.
osPathToText :: OsPath -> Text
osPathToText :: OsPath -> Text
osPathToText OsPath
path = FilePath -> Text
forall a b. ConvertibleStrings a b => a -> b
cs (IO FilePath -> FilePath
forall a. IO a -> a
unsafePerformIO (OsPath -> IO FilePath
forall (m :: * -> *). MonadThrow m => OsPath -> m FilePath
OsPath.decodeUtf OsPath
path))
{-# NOINLINE osPathToText #-}

-- | Allows using string literals as OsPath values with OverloadedStrings.
instance IsString OsPath where
    fromString :: FilePath -> OsPath
fromString FilePath
s = IO OsPath -> OsPath
forall a. IO a -> a
unsafePerformIO (FilePath -> IO OsPath
forall (m :: * -> *). MonadThrow m => FilePath -> m OsPath
OsPath.encodeUtf FilePath
s)
    {-# NOINLINE fromString #-}