1------------------------------------------------------------------------------
2-- Conversion to and from direct style stream
3------------------------------------------------------------------------------
6#define IS_STREAM IsStream t,
7#define FROM_STREAM fromStream
8#define TO_STREAM toStream
14#define STREAM K.Stream
17-- These definitions are dependent on what is imported as S
18{-# INLINE fromStreamS #-}
19fromStreamS :: (IS_STREAM Monad m) => S.Stream m a -> STREAM m a
20fromStreamS = FROM_STREAM . S.toStreamK
22{-# INLINE toStreamS #-}
23toStreamS :: (IS_STREAM Monad m) => STREAM m a -> S.Stream m a
24toStreamS = S.fromStreamK . TO_STREAM
26{-# INLINE toStreamD #-}
27toStreamD :: (IS_STREAM Monad m) => STREAM m a -> D.Stream m a
28toStreamD = D.fromStreamK . TO_STREAM
30------------------------------------------------------------------------------
32------------------------------------------------------------------------------
34{-# INLINE_EARLY drain #-}
35drain :: (IS_STREAM Monad m) => STREAM m a -> m ()
36drain m = D.drain $ D.fromStreamK (TO_STREAM m)
37{-# RULES "drain fallback to CPS" [1]
38 forall a. D.drain (D.fromStreamK a) = K.drain a #-}
40------------------------------------------------------------------------------
42------------------------------------------------------------------------------
46-- fromList = 'Prelude.foldr' 'K.cons' 'K.nil'
49-- Construct a stream from a list of pure values. This is more efficient than
50-- 'K.fromFoldable' for serial streams.
53{-# INLINE_EARLY fromList #-}
55fromList :: (Monad m, IsStream t) => [a] -> STREAM m a
57fromList :: Monad m => [a] -> STREAM m a
59fromList = fromStreamS . S.fromList
60{-# RULES "fromList fallback to StreamK" [1]
61 forall a. S.toStreamK (S.fromList a) = K.fromFoldable a #-}
63-- | Convert a stream into a list in the underlying monad.
67toList :: (IS_STREAM Monad m) => STREAM m a -> m [a]
68toList m = S.toList $ toStreamS m
70------------------------------------------------------------------------------
72------------------------------------------------------------------------------
75foldrM :: (IS_STREAM Monad m) => (a -> m b -> m b) -> m b -> STREAM m a -> m b
76foldrM step acc m = S.foldrM step acc $ toStreamS m
79foldrMx :: (IS_STREAM Monad m)
80 => (a -> m x -> m x) -> m x -> (m x -> m b) -> STREAM m a -> m b
81foldrMx step final project m = D.foldrMx step final project $ toStreamD m
84foldr :: (IS_STREAM Monad m) => (a -> b -> b) -> b -> STREAM m a -> m b
85foldr f z = foldrM (\a b -> f a <$> b) (return z)
87-- | Like 'foldlx'', but with a monadic step function.
90{-# INLINE foldlMx' #-}
93 => (x -> a -> m x) -> m x -> (x -> m b) -> STREAM m a -> m b
94foldlMx' step begin done m = S.foldlMx' step begin done $ toStreamS m
96-- | Strict left fold with an extraction function. Like the standard strict
97-- left fold, but applies a user supplied extraction function (the third
98-- argument) to the folded value at the end. This is designed to work with the
99-- @foldl@ library. The suffix @x@ is a mnemonic for extraction.
102{-# INLINE foldlx' #-}
104 (IS_STREAM Monad m) => (x -> a -> x) -> x -> (x -> b) -> STREAM m a -> m b
105foldlx' step begin done m = S.foldlx' step begin done $ toStreamS m
107-- | Strict left associative fold.
112 (IS_STREAM Monad m) => (b -> a -> b) -> b -> STREAM m a -> m b
113foldl' step begin m = S.foldl' step begin $ toStreamS m
117fold :: (IS_STREAM Monad m) => Fold m a b -> STREAM m a -> m b
118fold fld m = S.fold fld $ toStreamS m
120------------------------------------------------------------------------------
122------------------------------------------------------------------------------
124-- | Compare two streams for equality
128eqBy :: (IS_STREAM Monad m) =>
129 (a -> b -> Bool) -> STREAM m a -> STREAM m b -> m Bool
130eqBy f m1 m2 = D.eqBy f (toStreamD m1) (toStreamD m2)
132-- | Compare two streams
137 :: (IS_STREAM Monad m)
138 => (a -> b -> Ordering) -> STREAM m a -> STREAM m b -> m Ordering
139cmpBy f m1 m2 = D.cmpBy f (toStreamD m1) (toStreamD m2)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list