polysemy-scoped-fs-0.1.0.0: Well-typed filesystem operation effects.
Copyright(c) Hisaket VioletRed 2022
LicenseAGPL-3.0-or-later
Maintainerhisaket@outlook.jp
Stabilityexperimental
PortabilityPOSIX
Safe HaskellNone
LanguageHaskell2010

Polysemy.FS.Scoped.Text

Description

Example:

>>> import qualified Polysemy.SequentialAccess as SA
>>> import qualified Polysemy.SequentialAccess.Text as SAT
>>> import Polysemy ( runFinal, embedToFinal, embed )
>>> import Polysemy.Resource ( resourceToIOFinal )
>>> import Polysemy.Path
>>> import Polysemy.FS.Scoped ( scopedFile, AccessMode (RwAccess) )
>>> import Control.Monad.Extra ( whenM )
>>> import System.Directory ( doesFileExist, removeFile )
>>> import Control.Exception ( throwIO )
>>> :{
runFinal $ embedToFinal $ resourceToIOFinal $ rwAccessToIO do 
    let path = [absfile|/tmp/polysemy-scoped-fs-test|]
    embed $ whenM (doesFileExist $ toFilePath path) $
        throwIO $ userError "Abort to prevent overwriting."
    scopedFile @RwAccess path do
        SA.extend "This text will be deleted."
        SA.resize SA.NullSize
        SA.extend "foo"
        SA.extend "bar"
        SA.seek SA.TOF
        embed . print =<< SA.read SA.ToEnd
    embed $ removeFile $ toFilePath path
:}
"foobar"
Synopsis

Documentation

readAccessToIO :: Members '[Embed IO, Resource] r => Access TextFormat ReadAccess (ReadLine ': (ReadToEnd ': Cursor)) r b Source #

An interpreter for read open mode with text.

writeAccessToIO :: Members '[Embed IO, Resource] r => Access TextFormat WriteAccess (Extend ': (Clear ': Cursor)) r b Source #

An interpreter for write open mode with text.

rwAccessToIO :: Members '[Embed IO, Resource] r => Access TextFormat RwAccess (ReadLine ': (ReadToEnd ': (Extend ': (Clear ': Cursor)))) r b Source #

An interpreter for read and write open mode with text.

appendAccessToIO :: Members '[Embed IO, Resource] r => Access TextFormat AppendAccess '[Append, Clear] r b Source #

An interpreter for append open mode with text.