on develop help sign in
Add convenience functions: 'ffor2' & 'ffor3'
b4342f3Alexandre Esteves
Quickref.md+8
@@ -98,6 +98,10 @@ Since MonadHold depends on MonadSample, any [S] function also runs in [H] contex
98[ ] <> :: Monoid a => Behavior a -> Behavior a -> Behavior a
98[ ] <> :: Monoid a => Behavior a -> Behavior a -> Behavior a
99-- ... plus many more due to typeclass membership
99-- ... plus many more due to typeclass membership
100
100
101+-- Combine multiple behaviors via applicative instance
102+[ ] ffor2 :: Behavior a -> Behavior b -> (a -> b -> c) -> Behavior c
103+[ ] ffor3 :: Behavior a -> Behavior b -> Behavior c -> (a -> b -> c -> d) -> Behavior d
104+
101-- Behavior to Behavior by sampling current values
105-- Behavior to Behavior by sampling current values
102[S] sample :: Behavior a -> m a
106[S] sample :: Behavior a -> m a
103[ ] pull :: m a -> Behavior a
107[ ] pull :: m a -> Behavior a
@@ -135,6 +139,10 @@ Since MonadHold depends on MonadSample, any [S] function also runs in [H] contex
135[ ] >>= :: Dynamic a -> (a -> Dynamic b) -> Dynamic b
139[ ] >>= :: Dynamic a -> (a -> Dynamic b) -> Dynamic b
136[ ] zipDynWith :: (a -> b -> c) -> Dynamic a -> Dynamic b -> Dynamic c
140[ ] zipDynWith :: (a -> b -> c) -> Dynamic a -> Dynamic b -> Dynamic c
137
141
142+-- Combine multiple dynamics via applicative instance
143+[ ] ffor2 :: Dynamic a -> Dynamic b -> (a -> b -> c) -> Dynamic c
144+[ ] ffor3 :: Dynamic a -> Dynamic b -> Dynamic c -> (a -> b -> c -> d) -> Dynamic d
145+
138-- Efficient one-to-many fanout
146-- Efficient one-to-many fanout
139[ ] demux :: Ord k => Dynamic k -> Demux k
147[ ] demux :: Ord k => Dynamic k -> Demux k
140[ ] demuxed :: Eq k => Demux k -> k -> Dynamic Bool
148[ ] demuxed :: Eq k => Demux k -> k -> Dynamic Bool
src/Reflex/Class.hs+10
@@ -131,6 +131,8 @@ module Reflex.Class
131 , mapMapWithAdjustWithMove
131 , mapMapWithAdjustWithMove
132 -- * Miscellaneous convenience functions
132 -- * Miscellaneous convenience functions
133 , ffor
133 , ffor
134+ , ffor2
135+ , ffor3
134 -- * Deprecated functions
136 -- * Deprecated functions
135 , MonadAdjust
137 , MonadAdjust
136 , appendEvents
138 , appendEvents
@@ -576,6 +578,14 @@ pushAlways f = push (fmap Just . f)
576ffor :: Functor f => f a -> (a -> b) -> f b
578ffor :: Functor f => f a -> (a -> b) -> f b
577ffor = flip fmap
579ffor = flip fmap
578
580
581+-- | Rotated version of 'liftA2'.
582+ffor2 :: Applicative f => f a -> f b -> (a -> b -> c) -> f c
583+ffor2 a b f = liftA2 f a b
584+
585+-- | Rotated version of 'liftA3'.
586+ffor3 :: Applicative f => f a -> f b -> f c -> (a -> b -> c -> d) -> f d
587+ffor3 a b c f = liftA3 f a b c
588+
579instance Reflex t => Applicative (Behavior t) where
589instance Reflex t => Applicative (Behavior t) where
580 pure = constant
590 pure = constant
581 f <*> x = pull $ sample f `ap` sample x
591 f <*> x = pull $ sample f `ap` sample x