iterate

Creating an Enumeratee from a stateful algorithm

蹲街弑〆低调 提交于 2020-01-02 09:56:30
问题 I have a stateful algorithm that incrementally takes input and incrementally produces output. The inputs and outputs are unrelated in number; i.e. an input may produce zero or more outputs. I am attempting to turn it into an Enumeratee in the Play Framework, but I am having difficulty getting started. My algorithm has local mutable state and synchronous operations and looks something like this var state = 'foo var i = input() while (i != null) { if (state == 'foo && i >= 0) { // 2 outputs,

Why does my Mapreduce implementation (real world haskell) using iteratee IO also fails with “Too many open files”

♀尐吖头ヾ 提交于 2019-12-30 04:22:08
问题 I am implementing a haskell program wich compares each line of a file with each other line in the file. Which can be implemented single threaded as follows distance :: Int -> Int -> Int distance a b = (a-b)*(a-b) sumOfDistancesOnSmallFile :: FilePath -> IO Int sumOfDistancesOnSmallFile path = do fileContents <- readFile path return $ allDistances $ map read $ lines $ fileContents where allDistances (x:xs) = (allDistances xs) + ( sum $ map (distance x) xs) allDistances _ = 0 This will run in O

Using Scalaz Stream for parsing task (replacing Scalaz Iteratees)

房东的猫 提交于 2019-12-29 10:09:03
问题 Introduction I use Scalaz 7's iteratees in a number of projects, primarily for processing large-ish files. I'd like to start switching to Scalaz streams, which are designed to replace the iteratee package (which frankly is missing a lot of pieces and is kind of a pain to use). Streams are based on machines (another variation on the iteratee idea), which have also been implemented in Haskell. I've used the Haskell machines library a bit, but the relationship between machines and streams isn't

Using Scalaz Stream for parsing task (replacing Scalaz Iteratees)

允我心安 提交于 2019-12-29 10:08:33
问题 Introduction I use Scalaz 7's iteratees in a number of projects, primarily for processing large-ish files. I'd like to start switching to Scalaz streams, which are designed to replace the iteratee package (which frankly is missing a lot of pieces and is kind of a pain to use). Streams are based on machines (another variation on the iteratee idea), which have also been implemented in Haskell. I've used the Haskell machines library a bit, but the relationship between machines and streams isn't

Is there an Iteratee-like concept which pulls data from multiple sources?

心已入冬 提交于 2019-12-29 06:13:27
问题 It is possible to pull on demand from a number (say two for simplicity) of sources using streams (lazy lists). Iteratees can be used to process data coming from a single source. Is there an Iteratee-like functional concept for processing multiple input sources? I could imagine an Iteratee whose state signals from which source does it want to pull. 回答1: To do this using pipes you nest the Pipe monad transformer within itself, once for each producer you wish to interact with. For example:

pandas edit a cell value with itertuples

烈酒焚心 提交于 2019-12-22 09:37:01
问题 I would like speed my code, so I don't like to use double for: my code: for c in range(0, n-1): for l in range(0,n-c-1): df2.ix[l,c]=C_back(l,c,df) I would like to use for x in df.itertuples(): but I don't know how to modify a specific cell value. thanks 回答1: use stack for mytuple, value in df.stack().iteritems(): print(mytuple, value) consider the df df = pd.DataFrame(np.arange(9).reshape(-1, 3), list('ABC'), list('XYZ')) df for mytuple, value in df.stack().iteritems(): print(mytuple, value)

Enumerator vs Iterator in scala and java

混江龙づ霸主 提交于 2019-12-22 08:33:48
问题 What is the difference between Enumerator and Iterator? Per my understanding Enumerator is not a fancy alias for enum in Java. Rather, it seems to be a traversal technique similar to an Iterator . So is anyone able to compare and contrast Enumerator and Iterator ? Also, I see a usage in Play as val data = getDataStream val dataContent: Enumerator[Array[Byte]] = Enumerator.fromStream(data) EDIT: I am inclined to think that Enumerator gives us actual chunks of data, whereas Iterator gives us

Iteratees in Scala that use lazy evaluation or fusion?

Deadly 提交于 2019-12-21 03:35:11
问题 I have heard that iteratees are lazy, but how lazy exactly are they? Alternatively, can iteratees be fused with a postprocessing function, so that an intermediate data structure does not have to be built? Can I in my iteratee for example build a 1 million item Stream[Option[String]] from a java.io.BufferedReader , and then subsequently filter out the None s, in a compositional way, without requiring the entire Stream to be held in memory? And at the same time guarantee that I don't blow the

How is ReactiveMongo implemented so that it is considered non-blocking?

允我心安 提交于 2019-12-20 12:34:23
问题 Reading the documentation about the Play Framework and ReactiveMongo leads me to believe that ReactiveMongo works in such a way that it uses few threads and never blocks. However, it seems that the communication from the Play application to the Mongo server would have to happen on some thread somewhere . How is this implemented? Links to the source code for Play, ReactiveMongo, Akka, etc. would also be very appreciated. The Play Framework includes some documentation about this on this page

Broadcasting messages in Play Framework WebSockets

◇◆丶佛笑我妖孽 提交于 2019-12-19 04:37:00
问题 I'm pushing messages in Play Framework WebSockets using Concurrent.unicast[JsValue] , and I want to optimize sending the same message to multiple users. Is it possible to broadcast message using somehow multiple Concurrent.Channel ? 回答1: Short answer Maintain separate channel for each user and have groups associated with users Long answer package controllers import akka.actor.Actor import play.api.libs.iteratee.Enumerator import play.api.libs.iteratee.Concurrent.Channel import play.api.libs