on develop help sign in
Merge pull request #191 from alexfmpe/ffor-multi
d2a084dRyan Trinkle
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
@@ -122,6 +122,8 @@ module Reflex.Class
122 , filterRight
122 , filterRight
123 -- * Miscellaneous convenience functions
123 -- * Miscellaneous convenience functions
124 , ffor
124 , ffor
125+ , ffor2
126+ , ffor3
125 -- * Deprecated functions
127 -- * Deprecated functions
126 , appendEvents
128 , appendEvents
127 , onceE
129 , onceE
@@ -434,6 +436,14 @@ pushAlways f = push (fmap Just . f)
434ffor :: Functor f => f a -> (a -> b) -> f b
436ffor :: Functor f => f a -> (a -> b) -> f b
435ffor = flip fmap
437ffor = flip fmap
436
438
439+-- | Rotated version of 'liftA2'.
440+ffor2 :: Applicative f => f a -> f b -> (a -> b -> c) -> f c
441+ffor2 a b f = liftA2 f a b
442+
443+-- | Rotated version of 'liftA3'.
444+ffor3 :: Applicative f => f a -> f b -> f c -> (a -> b -> c -> d) -> f d
445+ffor3 a b c f = liftA3 f a b c
446+
437instance Reflex t => Applicative (Behavior t) where
447instance Reflex t => Applicative (Behavior t) where
438 pure = constant
448 pure = constant
439 f <*> x = pull $ sample f `ap` sample x
449 f <*> x = pull $ sample f `ap` sample x