on develop help sign in
Merge pull request #60 from HectorAE/develop
49a5160Ryan Trinkle
src/Reflex/Class.hs+15
@@ -36,6 +36,8 @@ module Reflex.Class
36 , mergeWith
36 , mergeWith
37 -- ** Breaking up 'Event's
37 -- ** Breaking up 'Event's
38 , splitE
38 , splitE
39+ , fanEither
40+ , fanThese
39 , fanMap
41 , fanMap
40 , dmapToThese
42 , dmapToThese
41 , EitherTag (..)
43 , EitherTag (..)
@@ -95,6 +97,7 @@ import Data.Bifunctor
95import Data.Dependent.Map (DMap, DSum (..), GCompare (..), GOrdering (..))
97import Data.Dependent.Map (DMap, DSum (..), GCompare (..), GOrdering (..))
96import qualified Data.Dependent.Map as DMap
98import qualified Data.Dependent.Map as DMap
97import Data.Dependent.Sum (ShowTag (..))
99import Data.Dependent.Sum (ShowTag (..))
100+import Data.Either
98import Data.Foldable
101import Data.Foldable
99import Data.Functor.Bind hiding (join)
102import Data.Functor.Bind hiding (join)
100import qualified Data.Functor.Bind as Bind
103import qualified Data.Functor.Bind as Bind
@@ -600,6 +603,18 @@ mergeList es = mergeWith (<>) $ map (fmap (:|[])) es
600mergeMap :: (Reflex t, Ord k) => Map k (Event t a) -> Event t (Map k a)
603mergeMap :: (Reflex t, Ord k) => Map k (Event t a) -> Event t (Map k a)
601mergeMap = fmap dmapToMap . merge . mapWithFunctorToDMap
604mergeMap = fmap dmapToMap . merge . mapWithFunctorToDMap
602
605
606+-- | Split the event into separate events for 'Left' and 'Right' values.
607+fanEither :: Reflex t => Event t (Either a b) -> (Event t a, Event t b)
608+fanEither e = let justLeft = either Just (const Nothing)
609+ justRight = either (const Nothing) Just
610+ in
611+ (fmapMaybe justLeft e, fmapMaybe justRight e)
612+
613+-- | Split the event into separate events for 'This' and 'That' values,
614+-- allowing them to fire simultaneously when the input value is 'These'.
615+fanThese :: Reflex t => Event t (These a b) -> (Event t a, Event t b)
616+fanThese e = (fmapMaybe justThis e, fmapMaybe justThat e)
617+
603-- | Split the event into an 'EventSelector' that allows efficient selection of
618-- | Split the event into an 'EventSelector' that allows efficient selection of
604-- the individual 'Event's.
619-- the individual 'Event's.
605fanMap :: (Reflex t, Ord k) => Event t (Map k a) -> EventSelector t (Const2 k a)
620fanMap :: (Reflex t, Ord k) => Event t (Map k a) -> EventSelector t (Const2 k a)