on develop help sign in
Add convenience functions: 'ffor2' & 'ffor3'
commitb4342f399d9a0ba98a31bcaa631fc14ef168243b authorAlexandre Esteves <alexandre.fmp.esteves@gmail.com> dateSun 6 May 2018, 20:46 (8 years ago) parent9f3356f
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
@@ -131,6 +131,8 @@ module Reflex.Class
131131 , mapMapWithAdjustWithMove
132132 -- * Miscellaneous convenience functions
133133 , ffor
134+ , ffor2
135+ , ffor3
134136 -- * Deprecated functions
135137 , MonadAdjust
136138 , appendEvents
@@ -576,6 +578,14 @@ pushAlways f = push (fmap Just . f)
576578ffor :: Functor f => f a -> (a -> b) -> f b
577579ffor = flip fmap
578580
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+
579589instance Reflex t => Applicative (Behavior t) where
580590 pure = constant
581591 f <*> x = pull $ sample f `ap` sample x