Permalink
Browse files

FRP.Euphoria.Event: more efficient partitionEithersE

  • Loading branch information...
1 parent 2b15cbf commit fd3a87823c092cbceaffe7ff21221383050d3d62 @liyang liyang committed Mar 13, 2013
Showing with 9 additions and 8 deletions.
  1. +8 −7 FRP/Euphoria/Event.hs
  2. +1 −1 euphoria.cabal
View
@@ -111,12 +111,13 @@ module FRP.Euphoria.Event
, networkToList
) where
+import Control.Arrow ((&&&))
import Control.Applicative
import Control.DeepSeq
import Control.Monad (join, replicateM)
import Control.Monad.Fix
import Data.Default
-import Data.Either (lefts, rights)
+import Data.Either (partitionEithers, lefts, rights)
import Data.List (foldl')
import Data.Monoid
import Data.Maybe
@@ -409,19 +410,19 @@ generalPrefixE prefixTaker (Event evt) = do
-- doesn't reduce to prev. This means each iteration
-- the signal gets bigger and more expensive to evaluate.
--- | Split a stream of 'Either's into two, based on tags.
+-- | Split a stream of 'Either's into two, based on tags. This needs to be
+-- in SignalGen in order to memoise the intermediate result.
partitionEithersE :: Event (Either a b) -> SignalGen (Event a, Event b)
-partitionEithersE evt = do
- evt' <- memoE evt
- return (leftE evt', rightE evt')
+partitionEithersE (Event eithersS) = (Event . fmap fst &&& Event . fmap snd)
+ <$> memoS (partitionEithers <$> eithersS)
-- | Keep occurrences which are Left.
leftE :: Event (Either e a) -> Event e
-leftE (Event evt) = Event $ lefts <$> evt
+leftE (Event eithersS) = Event (lefts <$> eithersS)
-- | Keep occurrences which are Right.
rightE :: Event (Either e a) -> Event a
-rightE (Event evt) = Event $ rights <$> evt
+rightE (Event eithersS) = Event (rights <$> eithersS)
-- | @groupByE eqv evt@ creates a stream of event streams, each corresponding
-- to a span of consecutive occurrences of equivalent elements in the original
View
@@ -2,7 +2,7 @@
-- see http://haskell.org/cabal/users-guide/
name: euphoria
-version: 0.4.7.0
+version: 0.4.8.0
synopsis: Dynamic network FRP with events and continuous values
description:

0 comments on commit fd3a878

Please sign in to comment.