@@ -1419,112 +1419,6 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
1419-- for serial operations even though it needs to deal with the concurrency
1419-- for serial operations even though it needs to deal with the concurrency
1420-- capability.
1420-- capability.
1424−-- We can use @unfoldr@ and @uncons@ to convert one streaming type to another.
1426−-- Interop with @vector@:
1429−-- import "Streamly.Prelude" (SerialT)
1430−-- import qualified "Streamly.Prelude" as Stream
1431−-- import qualified Data.Vector.Fusion.Stream.Monadic as Vector
1433−-- -- | vector to streamly
1434−-- fromVector :: (Stream.IsStream t, Monad m) => Vector.Stream m a -> t m a
1435−-- fromVector = Stream.unfoldrM unconsV
1438−-- r <- Vector.null v
1440−-- then return Nothing
1442−-- h <- Vector.head v
1443−-- return $ Just (h, Vector.tail v)
1445−-- -- | streamly to vector
1446−-- toVector :: Monad m => SerialT m a -> Vector.Stream m a
1447−-- toVector = Vector.unfoldrM (Stream.uncons . Stream.adapt)
1450−-- Stream.toList (fromVector (Vector.fromList [1..3])) >>= print
1451−-- Vector.toList (toVector (Stream.fromFoldable [1..3])) >>= print
1454−-- Interop with @pipes@:
1457−-- import "Streamly.Prelude" (IsStream, MonadAsync, SerialT)
1458−-- import qualified "Streamly.Prelude" as Stream
1459−-- import qualified Pipes as Pipe
1460−-- import qualified Pipes.Prelude as Pipe
1462−-- -- | pipes to streamly
1463−-- fromPipes :: (IsStream t, MonadAsync m) => Pipe.Producer a m () -> t m a
1464−-- fromPipes = Stream.'unfoldrM' unconsP
1466−-- -- Adapt Pipe.next to return a Maybe instead of Either
1467−-- unconsP p = either (const Nothing) Just <$> Pipe.next p
1469−-- -- | streamly to pipes
1470−-- toPipes :: Monad m => SerialT m a -> Pipe.Producer a m ()
1471−-- toPipes = Pipe.unfoldr unconsEither
1473−-- -- Adapt Stream.uncons to return an Either instead of Maybe
1474−-- unconsEither :: Monad m => SerialT m a -> m (Either () (a, SerialT m a))
1475−-- unconsEither s = maybe (Left ()) Right <$> Stream.'uncons' s
1478−-- Stream.'toList' (fromPipes (Pipe.each [1..3])) >>= print
1479−-- Pipe.toListM (toPipes (Stream.'fromFoldable' [1..3])) >>= print
1482−-- Interop with @streaming@:
1485−-- import "Streamly.Prelude" (IsStream, MonadAsync, SerialT)
1486−-- import qualified "Streamly.Prelude" as Stream
1487−-- import qualified Streaming as Streaming
1488−-- import qualified Streaming.Prelude as Streaming
1490−-- -- | streaming to streamly
1491−-- fromStreaming :: (IsStream t, MonadAsync m) => Streaming.Stream (Streaming.Of a) m () -> t m a
1492−-- fromStreaming = Stream.'unfoldrM' Streaming.uncons
1494−-- -- | streamly to streaming
1495−-- toStreaming :: Monad m => SerialT m a -> Streaming.Stream (Streaming.Of a) m ()
1496−-- toStreaming = Streaming.unfoldr unconsEither
1498−-- -- Adapt Stream.uncons to return an Either instead of Maybe
1499−-- unconsEither :: Monad m => SerialT m a -> m (Either () (a, SerialT m a))
1500−-- unconsEither s = maybe (Left ()) Right <$> Stream.'uncons' s
1503−-- Stream.'toList' (fromStreaming (Streaming.each [1..3])) >>= print
1504−-- Streaming.toList (toStreaming (Stream.'fromFoldable' [1..3])) >>= print
1507−-- Interop with @conduit@:
1510−-- import "Streamly.Prelude" (IsStream, MonadAsync, SerialT)
1511−-- import qualified "Streamly.Prelude" as Stream
1512−-- import qualified Data.Conduit as Conduit
1513−-- import qualified Data.Conduit.List as Conduit
1515−-- -- | conduit to streamly
1516−-- fromConduit :: (IsStream t, MonadAsync m) => Conduit.ConduitT () a m () -> t m a
1517−-- fromConduit = Stream.unfoldrM Conduit.unconsM . Conduit.sealConduitT
1519−-- -- | streamly to conduit
1520−-- toConduit :: Monad m => SerialT m a -> Conduit.ConduitT i a m ()
1521−-- toConduit = Conduit.unfoldM Stream.'uncons'
1524−-- Stream.'toList' (fromConduit (Conduit.sourceList [1..3])) >>= print
1525−-- Conduit.runConduit (toConduit (Stream.'fromFoldable' [1..3]) Conduit..| Conduit.consume) >>= print
1528-- $comparison
1422-- $comparison
1530-- List transformers and logic programming monads also provide a product style
1424-- List transformers and logic programming monads also provide a product style