Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. First steps with Streaming library (aquagnu)
----------------------------------------------------------------------
Message: 1
Date: Sat, 27 May 2017 18:30:28 +0300
From: aquagnu <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] First steps with Streaming library
Message-ID: <[email protected]>
Content-Type: text/plain; charset=US-ASCII
I'm trying to start working with Streaming package. First attempt
is to simulate source of stream items (I call the function "gen")
and some processor ("proc"). Both should be stateful: to be able
to sabe some info about processing steps, etc.
...
import Streaming
import qualified Streaming.Prelude as S
...
gen :: S.Stream (S.Of Int) IO [String]
gen = do
S.yield 1000
S.yield 2000
x <- lift getLine
return ["a", "b", "c", x] -- results
proc :: S.Stream (S.Of Int) IO [String] -> S.Stream (S.Of Int) IO [String]
proc str = do
e <- str
lift $ print "Enter x:"
x <- lift getLine
return $ e ++ [" -- " ++ x] -- put stream items in result
main :: IO
main = do
s <- S.mapM_ print $ S.map show gen
p <- S.mapM_ print $ proc gen
putStr "s: " >> print s
putStr "p: " >> print p
And I try to simulate "piping" between "gen" and "proc", seems that
function application is enought to compose producers and consumers. But
this snippet is not correct: "e <- str" extracts element not from
stream, but from results (of "gen"). Even more, I don't know how to
"yield" new items, based on stream items. Something like "await" of
Conduit, or like in Python "for e in str: ... yield modified(e)...". Is
it possible to do it with "do" notation?
---
Best,
Paul
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 107, Issue 14
******************************************