Hi, I’m new to PureScript and I’m trying to make a function that takes a file path and returns a readline interface. The stream passed into RL.createInterface
is a normal readable stream or a gunzip’ed readable stream depending on the extension of the file. But this doesn’t compile:
createInterface :: String -> Effect RL.Interface
createInterface path = do
stream' <- stream
RL.createInterface stream' mempty
where stream = case (path # endsWith ".gz") of
false -> createReadStream path
true -> do
rs <- createReadStream path
gz <- createGunzip
_ <- rs `pipe` gz
pure gz
I know that createReadStream
returns Effect Readable ()
, and here createGunzip
returns Effect Duplex
. How can this be made to work? Looking at the docs for Duplex, it seems that it can be treated as Readable
.
By the way, refactoring the function into this form allows it to work:
createInterface :: String -> Effect RL.Interface
createInterface path = do
rs <- createReadStream path
case path # endsWith ".gz" of
false -> RL.createInterface rs mempty
true -> do
gz <- createGunzip
_ <- rs `pipe` gz
RL.createInterface gz mempty
But I’m still curious about why my original version doesn’t work.