diff options
author | michaelt <what_is_it_to_do_anything@yahoo.com> | 2015-05-03 21:38:59 -0400 |
---|---|---|
committer | michaelt <what_is_it_to_do_anything@yahoo.com> | 2015-05-03 21:38:59 -0400 |
commit | 5e387e52ab52117a1b245508232cd04d79fff47d (patch) | |
tree | 39e8fa426da06ba2dc8b25fa0f55db09d54c45cd /examples | |
parent | 77c322613ac2bddfb9604c63e4f2d486b8f6681e (diff) | |
download | text-pipes-5e387e52ab52117a1b245508232cd04d79fff47d.tar.gz text-pipes-5e387e52ab52117a1b245508232cd04d79fff47d.tar.zst text-pipes-5e387e52ab52117a1b245508232cd04d79fff47d.zip |
wibble examples
Diffstat (limited to 'examples')
-rw-r--r-- | examples/lines_url.hs | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/examples/lines_url.hs b/examples/lines_url.hs index b676656..ebc04e5 100644 --- a/examples/lines_url.hs +++ b/examples/lines_url.hs | |||
@@ -23,15 +23,17 @@ main = do | |||
23 | -- "http://www.gutenberg.org/files/10/10-h/10-h.htm" | 23 | -- "http://www.gutenberg.org/files/10/10-h/10-h.htm" |
24 | withManager tlsManagerSettings $ \m -> | 24 | withManager tlsManagerSettings $ \m -> |
25 | withHTTP req m $ \resp -> void $ runEffect $ | 25 | withHTTP req m $ \resp -> void $ runEffect $ |
26 | number_lines_of (responseBody resp ^. utf8 . lines) >-> toHandle IO.stdout | 26 | number_lines_of (responseBody resp ^. utf8 . lines) >-> toHandle IO.stdout |
27 | 27 | ||
28 | number_lines_of :: Monad m => FreeT (Producer Text m) m bad -> Producer Text m bad | 28 | number_lines_of :: Monad m => FreeT (Producer Text m) m r -> Producer Text m r |
29 | number_lines_of = number_loop (1 :: Int) where | 29 | number_lines_of = number_loop (1 :: Int) where |
30 | number_loop n freeProducers = do | 30 | number_loop n free = do |
31 | freeProducer <- lift $ runFreeT freeProducers | 31 | fproducer <- lift $ runFreeT free |
32 | case freeProducer of | 32 | case fproducer of |
33 | Pure badbytes -> do yield $ T.pack "\n" | 33 | Pure badbytes -> do |
34 | return badbytes -- these could be inspected ... | 34 | yield $ T.pack "\n" |
35 | Free p -> do yield $ T.pack ("\n" ++ show n ++ " ") | 35 | return badbytes -- these could be inspected ... |
36 | nextFreeProducers <- p | 36 | Free p -> do |
37 | number_loop (n+1) nextFreeProducers | 37 | yield $ T.pack ("\n" ++ show n ++ " ") |
38 | next_free <- p | ||
39 | number_loop (n+1) next_free | ||