on develop help sign in
Merge pull request #191 from alexfmpe/ffor-multi

Add convenience functions: 'ffor2' & 'ffor3'

commitd2a084d5340f015e59216f3bcff12f9d746eb2d7 authorRyan Trinkle <ryan.trinkle@gmail.com> dateThu 26 Jul 2018, 14:01 (8 years ago) parente52ce57b4342f3
2 files changed+18
Quickref.md+8 src/Reflex/Class.hs+10
Quickref.md+8
@@ -98,6 +98,10 @@ Since MonadHold depends on MonadSample, any [S] function also runs in [H] contex
9898[ ] <> :: Monoid a => Behavior a -> Behavior a -> Behavior a
9999-- ... plus many more due to typeclass membership
100100
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+
101105-- Behavior to Behavior by sampling current values
102106[S] sample :: Behavior a -> m a
103107[ ] pull :: m a -> Behavior a
@@ -135,6 +139,10 @@ Since MonadHold depends on MonadSample, any [S] function also runs in [H] contex
135139[ ] >>= :: Dynamic a -> (a -> Dynamic b) -> Dynamic b
136140[ ] zipDynWith :: (a -> b -> c) -> Dynamic a -> Dynamic b -> Dynamic c
137141
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+
138146-- Efficient one-to-many fanout
139147[ ] demux :: Ord k => Dynamic k -> Demux k
140148[ ] demuxed :: Eq k => Demux k -> k -> Dynamic Bool
src/Reflex/Class.hs+10
@@ -122,6 +122,8 @@ module Reflex.Class
122122 , filterRight
123123 -- * Miscellaneous convenience functions
124124 , ffor
125+ , ffor2
126+ , ffor3
125127 -- * Deprecated functions
126128 , appendEvents
127129 , onceE
@@ -434,6 +436,14 @@ pushAlways f = push (fmap Just . f)
434436ffor :: Functor f => f a -> (a -> b) -> f b
435437ffor = flip fmap
436438
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+
437447instance Reflex t => Applicative (Behavior t) where
438448 pure = constant
439449 f <*> x = pull $ sample f `ap` sample x