module HaskellWorks.Polysemy.Data.Text.Strict
( T.Text
, T.pack
, T.unpack
, T.singleton
, T.empty
, T.length
, T.compareLength
, T.null
, T.map
, T.intercalate
, T.intersperse
, T.transpose
, T.reverse
, T.replace
, T.toCaseFold
, T.toLower
, T.toUpper
, T.toTitle
, T.justifyLeft
, T.justifyRight
, T.center
, T.foldl
, T.foldl'
, T.foldl1
, T.foldl1'
, T.foldr
, T.foldr'
, T.foldr1
, T.concat
, T.concatMap
, T.any
, T.all
, T.maximum
, T.minimum
, T.isAscii
, T.scanl
, T.scanl1
, T.scanr
, T.scanr1
, T.mapAccumL
, T.mapAccumR
, T.replicate
, T.unfoldr
, T.unfoldrN
, T.take
, T.takeEnd
, T.drop
, T.dropEnd
, T.takeWhile
, T.takeWhileEnd
, T.dropWhile
, T.dropWhileEnd
, T.dropAround
, T.strip
, T.stripStart
, T.stripEnd
, T.splitAt
, T.breakOn
, T.breakOnEnd
, T.break
, T.span
, T.spanM
, T.spanEndM
, T.group
, T.groupBy
, T.inits
, T.tails
, T.splitOn
, T.split
, T.chunksOf
, T.lines
, T.words
, T.unlines
, T.unwords
, T.isPrefixOf
, T.isSuffixOf
, T.isInfixOf
, T.stripPrefix
, T.stripSuffix
, T.commonPrefixes
, T.filter
, T.breakOnAll
, T.find
, T.elem
, T.partition
, T.index
, T.findIndex
, T.count
, T.zip
, T.zipWith
, readFile
) where
import qualified Control.Exception as CE
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified GHC.Stack as GHC
import HaskellWorks.Polysemy.Prelude
import Polysemy
import Polysemy.Error
import Polysemy.Log
readFile :: ()
=> GHC.HasCallStack
=> Member (Error IOException) r
=> Member (Embed IO) r
=> Member Log r
=> FilePath
-> Sem r Text
readFile :: forall (r :: EffectRow).
(HasCallStack, Member (Error IOException) r, Member (Embed IO) r,
Member Log r) =>
FilePath -> Sem r Text
readFile FilePath
filePath =
(HasCallStack => Sem r Text) -> Sem r Text
forall a. HasCallStack => (HasCallStack => a) -> a
GHC.withFrozenCallStack ((HasCallStack => Sem r Text) -> Sem r Text)
-> (HasCallStack => Sem r Text) -> Sem r Text
forall a b. (a -> b) -> a -> b
$ do
Text -> Sem r ()
forall (r :: EffectRow).
(HasCallStack, Member Log r) =>
Text -> Sem r ()
info (Text -> Sem r ()) -> Text -> Sem r ()
forall a b. (a -> b) -> a -> b
$ Text
"Reading text file: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> FilePath -> Text
T.pack FilePath
filePath
Either IOException Text
r <- IO (Either IOException Text) -> Sem r (Either IOException Text)
forall (m :: * -> *) (r :: EffectRow) a.
Member (Embed m) r =>
m a -> Sem r a
embed (IO (Either IOException Text) -> Sem r (Either IOException Text))
-> IO (Either IOException Text) -> Sem r (Either IOException Text)
forall a b. (a -> b) -> a -> b
$ forall e a. Exception e => IO a -> IO (Either e a)
CE.try @IOException (IO Text -> IO (Either IOException Text))
-> IO Text -> IO (Either IOException Text)
forall a b. (a -> b) -> a -> b
$ FilePath -> IO Text
T.readFile FilePath
filePath
Either IOException Text -> Sem r Text
forall e (r :: EffectRow) a.
Member (Error e) r =>
Either e a -> Sem r a
fromEither Either IOException Text
r