Send Beginners mailing list submissions to
        beginners@haskell.org

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
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

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 <aqua...@gmail.com>
To: beginners@haskell.org
Subject: [Haskell-beginners] First steps with Streaming library
Message-ID: <20170527183028.01b9d...@gmail.com>
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
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


------------------------------

End of Beginners Digest, Vol 107, Issue 14
******************************************

Reply via email to