module HaskellWorks.Polysemy.Data.Text.Lazy
( LT.Text,
LT.pack,
LT.unpack,
LT.singleton,
LT.empty,
LT.length,
LT.compareLength,
LT.map,
LT.intercalate,
LT.intersperse,
LT.transpose,
LT.reverse,
LT.replace,
LT.toCaseFold,
LT.toLower,
LT.toUpper,
LT.toTitle,
LT.justifyLeft,
LT.justifyRight,
LT.center,
LT.foldl,
LT.foldl',
LT.foldl1,
LT.foldl1',
LT.foldr,
LT.foldr1,
LT.concat,
LT.concatMap,
LT.any,
LT.all,
LT.maximum,
LT.minimum,
LT.isAscii,
LT.scanl,
LT.scanl1,
LT.scanr,
LT.scanr1,
LT.mapAccumL,
LT.mapAccumR,
LT.replicate,
LT.unfoldr,
LT.unfoldrN,
LT.take,
LT.takeEnd,
LT.drop,
LT.dropEnd,
LT.takeWhile,
LT.takeWhileEnd,
LT.dropWhile,
LT.dropWhileEnd,
LT.dropAround,
LT.strip,
LT.stripStart,
LT.stripEnd,
LT.splitAt,
LT.breakOn,
LT.breakOnEnd,
LT.break,
LT.span,
LT.spanM,
LT.spanEndM,
LT.group,
LT.groupBy,
LT.inits,
LT.tails,
LT.splitOn,
LT.split,
LT.chunksOf,
LT.lines,
LT.words,
LT.unlines,
LT.unwords,
LT.isPrefixOf,
LT.isSuffixOf,
LT.isInfixOf,
LT.stripPrefix,
LT.stripSuffix,
LT.commonPrefixes,
LT.filter,
LT.breakOnAll,
LT.find,
LT.elem,
LT.partition,
LT.index,
LT.count,
LT.zip,
LT.zipWith,
readFile,
) where
import qualified Control.Exception as CE
import qualified Data.Text as T
import qualified Data.Text.Lazy as LT
import qualified Data.Text.Lazy.IO as LT
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 LT.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
LT.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