Skip to content

Commit 75b0360

Browse files
author
DDC
committed
Added yields.
1 parent bc8228d commit 75b0360

File tree

7 files changed

+23
-2
lines changed

7 files changed

+23
-2
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ cabal.sandbox.config
1818
.stack-work/
1919
cabal.project.local
2020
.HTF/
21+
Session.vim

streamy-pipes/lib/Streamy/Pipes.hs

+4
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ module Streamy.Pipes (
3636
, Streamy.Pipes.group
3737
, Streamy.Pipes.maps
3838
, Streamy.Pipes.concats
39+
, Streamy.Pipes.yields
3940
) where
4041

4142
import qualified Data.List
@@ -46,6 +47,7 @@ import qualified Pipes.Group as PG
4647

4748
import Control.Monad
4849
import Control.Monad.Trans.Class
50+
import Control.Monad.Trans.Free (liftF)
4951
import Control.Monad.IO.Class
5052

5153
import Lens.Micro.Extras (view)
@@ -158,3 +160,5 @@ maps f (Groups gs) = Groups $ PG.maps f gs
158160
concats :: Monad m => Groups a m r -> Stream a m r
159161
concats (Groups gs) = PG.concats gs
160162

163+
yields :: Monad m => Stream a m r -> Groups a m r
164+
yields producer = Groups $ liftF producer

streamy-sig/README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ package.
2929

3030
## Feature matrix
3131

32-
There are gaps in coverage in implementation of functions. Below is a feature matrix saying which functions are supported by which libraries.
32+
There are gaps in coverage in implementation of functions. Below is a feature
33+
matrix saying which functions are supported by which libraries.
3334

3435
Key | Module name
3536
----|--------------------------
@@ -85,5 +86,5 @@ There are gaps in coverage in implementation of functions. Below is a feature m
8586
| group | X | X | |
8687
| maps | X | X | |
8788
| concats | X | X | |
88-
89+
| yields | X | X | |
8990

streamy-sig/sig/Streamy.hsig

+2
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,6 @@ maps :: Monad m => (forall x. Stream a m x -> Stream b m x) -> Groups a m r -> G
8585

8686
concats :: Monad m => Groups a m r -> Stream a m r
8787

88+
yields :: Monad m => Stream a m r -> Groups a m r
89+
8890

streamy-streaming/lib/Streamy/Streaming.hs

+4
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ module Streamy.Streaming (
3737
, Streamy.Streaming.group
3838
, Streamy.Streaming.maps
3939
, Streamy.Streaming.concats
40+
, Streamy.Streaming.yields
4041
) where
4142

4243
import Control.Monad
@@ -161,6 +162,9 @@ maps f (Groups gs) = Groups $ Q.maps (getStream . f . Stream) gs
161162
concats :: Monad m => Groups a m r -> Stream a m r
162163
concats (Groups gs) = Stream $ Q.concats gs
163164

165+
yields :: Monad m => Stream a m r -> Groups a m r
166+
yields (Stream s) = Groups $ Q.yields s
167+
164168
--
165169
toTup :: Of a r -> (a,r)
166170
toTup = \(a :> r) -> (a,r)

streamy-testsuite/lib/Test/Grouping.hs

+8
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,17 @@ import Data.IORef
2020
grouping :: [TestTree]
2121
grouping =
2222
[ testCase "group-map-concats" basic
23+
, testCase "yields" testYields
2324
]
2425

2526
basic :: Assertion
2627
basic = do
2728
r <- Y.toList_ . Y.concats . Y.maps (\s -> Y.yield '<' *> s <* Y.yield '>') . Y.group $ Y.each "aabbcc"
2829
assertEqual "" "<aa><bb><cc>" r
30+
31+
testYields :: Assertion
32+
testYields = do
33+
r <- Y.toList_ . Y.concats . Y.yields $ Y.each "aaa" *> Y.each "bbb"
34+
assertEqual "" "aaabbb" r
35+
36+

streamy-testsuite/lib/Test/Grouping/Streamy.hsig

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ signature Test.Grouping.Streamy (
3232
, group
3333
, maps
3434
, concats
35+
, yields
3536
) where
3637

3738
import Prelude () -- weird confusions otherwise

0 commit comments

Comments
 (0)