[Haskell-cafe] servant streaming question
Zoran BoĆĄnjak
zoran.bosnjak at via.si
Fri Jun 30 18:00:03 UTC 2023
Hi all,
I would like to reuse some streaming functions from the turtle package in the context of the servant streaming handler.
Relevant references:
https://hackage.haskell.org/package/turtle-1.6.1/docs/Turtle-Shell.html
https://hackage.haskell.org/package/turtle-1.6.1/docs/Turtle-Prelude.html
https://hackage.haskell.org/package/servant-0.20/docs/Servant-Types-SourceT.html
As a simple example:
Turtle.Prelude.ls function represents stream of FilePaths (directory listing of some path)
ls :: FilePath -> Shell FilePath
Servant streaming is based around SourceT IO a, for example:
type ListFiles = "ls" :> StreamGet NewlineFraming PlainText (SourceT IO FilePath)
The problem is that the streaming (Shell a) is not exactly the same as servant's (SourceT IO a). But as far as I understand, they both represent "stream of values of type 'a'". My question is: Is a generic conversion function possible? Something like:
shellToSource :: forall a. Shell a -> SourceIO a
shellToSource = ??
... such that I could reuse the 'ls' and write a streaming servant handler like this:
listFilesHandler :: Handler (SourceIO FilePath)
listFilesHandler = pure $ shellToSource $ Turtle.Prelude.ls "somePath"
Appreciate any suggestion.
regards,
Zoran
More information about the Haskell-Cafe
mailing list