on master help sign in
tutorial: Update interop examples
c846b4eKirill Elagin
src/Streamly/Tutorial.hs+14−12
@@ -1567,24 +1567,25 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
1567-- Interop with @pipes@:
1567-- Interop with @pipes@:
1568--
1568--
1569-- @
1569-- @
1570−-- import "Streamly.Prelude" (SerialT)
1570+-- import "Streamly.Prelude" (IsStream, MonadAsync, SerialT)
1571-- import qualified "Streamly.Prelude" as S
1571-- import qualified "Streamly.Prelude" as S
1572-- import qualified Pipes as P
1572-- import qualified Pipes as P
1573-- import qualified Pipes.Prelude as P
1573-- import qualified Pipes.Prelude as P
1574--
1574--
1575-- -- | pipes to streamly
1575-- -- | pipes to streamly
1576−-- fromPipes :: (S.IsStream t, Monad m) => P.Producer a m r -> t m a
1576+-- fromPipes :: (IsStream t, MonadAsync m) => P.Producer a m () -> t m a
1577-- fromPipes = S.'unfoldrM' unconsP
1577-- fromPipes = S.'unfoldrM' unconsP
1578-- where
1578-- where
1579-- -- Adapt P.next to return a Maybe instead of Either
1579-- -- Adapt P.next to return a Maybe instead of Either
1580−-- unconsP p = P.next p >>= either (\\_ -> return Nothing) (return . Just)
1580+-- unconsP p = either (const Nothing) Just <$> P.next p
1581--
1581--
1582-- -- | streamly to pipes
1582-- -- | streamly to pipes
1583-- toPipes :: Monad m => SerialT m a -> P.Producer a m ()
1583-- toPipes :: Monad m => SerialT m a -> P.Producer a m ()
1584−-- toPipes = P.unfoldr unconsS
1584+-- toPipes = P.unfoldr unconsEither
1585-- where
1585-- where
1586-- -- Adapt S.uncons to return an Either instead of Maybe
1586-- -- Adapt S.uncons to return an Either instead of Maybe
1587−-- unconsS s = S.'uncons' s >>= maybe (return $ Left ()) (return . Right)
1587+-- unconsEither :: Monad m => SerialT m a -> m (Either () (a, SerialT m a))
1588+-- unconsEither s = maybe (Left ()) Right <$> S.'uncons' s
1588--
1589--
1589-- main = do
1590-- main = do
1590-- S.'toList' (fromPipes (P.each [1..3])) >>= print
1591-- S.'toList' (fromPipes (P.each [1..3])) >>= print
@@ -1594,25 +1595,26 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
1594-- Interop with @streaming@:
1595-- Interop with @streaming@:
1595--
1596--
1596-- @
1597-- @
1597−-- import "Streamly.Prelude" (SerialT, MonadAsync)
1598+-- import "Streamly.Prelude" (IsStream, MonadAsync, SerialT)
1598-- import qualified "Streamly.Prelude" as S
1599-- import qualified "Streamly.Prelude" as S
1599-- import qualified Streaming as SG
1600-- import qualified Streaming as SG
1600-- import qualified Streaming.Prelude as SG
1601-- import qualified Streaming.Prelude as SG
1601--
1602--
1602-- -- | streaming to streamly
1603-- -- | streaming to streamly
1603−-- fromStreaming :: (IsStream t, MonadAsync m) => SG.Stream (SG.Of a) m r -> t m a
1604+-- fromStreaming :: (IsStream t, MonadAsync m) => SG.Stream (SG.Of a) m () -> t m a
1604−-- fromStreaming = S.unfoldrM SG.uncons
1605+-- fromStreaming = S.'unfoldrM' SG.uncons
1605--
1606--
1606-- -- | streamly to streaming
1607-- -- | streamly to streaming
1607-- toStreaming :: Monad m => SerialT m a -> SG.Stream (SG.Of a) m ()
1608-- toStreaming :: Monad m => SerialT m a -> SG.Stream (SG.Of a) m ()
1608−-- toStreaming = SG.unfoldr unconsS
1609+-- toStreaming = SG.unfoldr unconsEither
1609-- where
1610-- where
1610-- -- Adapt S.uncons to return an Either instead of Maybe
1611-- -- Adapt S.uncons to return an Either instead of Maybe
1611−-- unconsS s = S.'uncons' s >>= maybe (return $ Left ()) (return . Right)
1612+-- unconsEither :: Monad m => SerialT m a -> m (Either () (a, SerialT m a))
1613+-- unconsEither s = maybe (Left ()) Right <$> S.'uncons' s
1612--
1614--
1613-- main = do
1615-- main = do
1614−-- S.toList (fromStreaming (SG.each [1..3])) >>= print
1616+-- S.'toList' (fromStreaming (SG.each [1..3])) >>= print
1615−-- SG.toList (toStreaming (S.fromFoldable [1..3])) >>= print
1617+-- SG.toList (toStreaming (S.'fromFoldable' [1..3])) >>= print
1616-- @
1618-- @
1617--
1619--
1618-- Interop with @conduit@:
1620-- Interop with @conduit@: