@@ -61,6 +61,7 @@ module Streamly.Internal.Prelude
61 , K.fromFoldable
61 , K.fromFoldable
62 , fromFoldableM
62 , fromFoldableM
63 , fromPrimVar
63 , fromPrimVar
65 -- ** Time related
66 -- ** Time related
66 , currentTime
67 , currentTime
@@ -277,6 +278,7 @@ module Streamly.Internal.Prelude
278 -- ** Nested Streams
279 -- ** Nested Streams
279 , concatMapM
280 , concatMapM
280 , concatUnfold
282 , concatUnfold
281 , concatUnfoldInterleave
283 , concatUnfoldInterleave
282 , concatUnfoldRoundrobin
284 , concatUnfoldRoundrobin
@@ -905,6 +907,19 @@ fromHandle h = go
905fromPrimVar :: (IsStream t, MonadIO m, Prim a) => Var IO a -> t m a
907fromPrimVar :: (IsStream t, MonadIO m, Prim a) => Var IO a -> t m a
906fromPrimVar = fromStreamD . D.fromPrimVar
908fromPrimVar = fromStreamD . D.fromPrimVar
910+-- | Takes a callback setter function and provides it with a callback. The
911+-- callback when invoked adds a value at the tail of the stream. Returns a
912+-- stream of values generated by the callback.
916+{-# INLINE fromCallback #-}
917+fromCallback :: MonadAsync m => ((a -> m ()) -> m ()) -> SerialT m a
918+fromCallback setCallback = concatM $ do
919+ (callback, stream) <- D.newCallbackStream
920+ setCallback callback
908------------------------------------------------------------------------------
923------------------------------------------------------------------------------
909-- Time related
924-- Time related
910------------------------------------------------------------------------------
925------------------------------------------------------------------------------
@@ -2612,6 +2627,15 @@ roundrobin m1 m2 = fromStreamD $ D.roundRobin (toStreamD m1) (toStreamD m2)
2612concatMapM :: (IsStream t, Monad m) => (a -> m (t m b)) -> t m a -> t m b
2627concatMapM :: (IsStream t, Monad m) => (a -> m (t m b)) -> t m a -> t m b
2613concatMapM f m = fromStreamD $ D.concatMapM (fmap toStreamD . f) (toStreamD m)
2628concatMapM f m = fromStreamD $ D.concatMapM (fmap toStreamD . f) (toStreamD m)
2630+-- | Given a stream value in the underlying monad, lift and join the underlying
2631+-- monad with the stream monad.
2635+{-# INLINE concatM #-}
2636+concatM :: (IsStream t, Monad m) => m (t m a) -> t m a
2637+concatM generator = concatMapM (\() -> generator) (K.yield ())
2615-- | Like 'concatMap' but uses an 'Unfold' for stream generation. Unlike
2639-- | Like 'concatMap' but uses an 'Unfold' for stream generation. Unlike
2616-- 'concatMap' this can fuse the 'Unfold' code with the inner loop and
2640-- 'concatMap' this can fuse the 'Unfold' code with the inner loop and
2617-- therefore provide many times better performance.
2641-- therefore provide many times better performance.