In short, yes I think it should be possible. But messing with Shell / Fold always feels like doing a brain teaser rather than programming. If you figure it out, I would like to hear about it. :P

On Fri, 30 Jun 2023 at 21:00, Zoran BoĆĄnjak <zoran.bosnjak@via.si> wrote:
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
_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.