Skip to content
Discussion options

You must be logged in to vote

The following ensures an effect FileSystemE supports reading a stream of bytes from a file, with an additional Error effect inside the stream.

newtype ReadFileError = ReadFileIOException IOException deriving Show

data FileSystemE :: Effect where
  ReadFile :: FilePath -> FileSystemE (Eff es) (Stream (Eff (Error ReadFileError : es)) Word8)
  
readFile :: (FileSystemE :> es) => FilePath -> Eff es (Stream (Eff (Error ReadFileError : es)) Word8)
readFile = Eff.send . ReadFile

runFileSystemIO = Eff.interpret \env -> \case
  (ReadFile path) -> Eff.localSeqLift env \lift -> pure
    $ onStreamException (throwError . ReadFileIOException)
    $ Stream.morphInner (Eff.raise . lift) $ Streamly.File.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@jerbaroo
Comment options

Answer selected by jerbaroo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants