on develop help sign in
Merge pull request #128 from samtay/convenience-func
0ff3483Ryan Trinkle
src/Reflex/Class.hs+10
@@ -100,6 +100,8 @@ module Reflex.Class
100 , FunctorMaybe (..)
100 , FunctorMaybe (..)
101 , fforMaybe
101 , fforMaybe
102 , ffilter
102 , ffilter
103+ , filterLeft
104+ , filterRight
103 -- * Miscellaneous convenience functions
105 -- * Miscellaneous convenience functions
104 , ffor
106 , ffor
105 , MonadAdjust (..)
107 , MonadAdjust (..)
@@ -575,6 +577,14 @@ fforMaybe = flip fmapMaybe
575ffilter :: FunctorMaybe f => (a -> Bool) -> f a -> f a
577ffilter :: FunctorMaybe f => (a -> Bool) -> f a -> f a
576ffilter f = fmapMaybe $ \x -> if f x then Just x else Nothing
578ffilter f = fmapMaybe $ \x -> if f x then Just x else Nothing
577
579
580+-- | Filter 'Left's from 'f (Either a b)' into 'a'.
581+filterLeft :: FunctorMaybe f => f (Either a b) -> f a
582+filterLeft = fmapMaybe (either Just (const Nothing))
583+
584+-- | Filter 'Right's from 'f (Either a b)' into 'b'.
585+filterRight :: FunctorMaybe f => f (Either a b) -> f b
586+filterRight = fmapMaybe (either (const Nothing) Just)
587+
578-- | Left-biased event union (prefers left event on simultaneous
588-- | Left-biased event union (prefers left event on simultaneous
579-- occurrence).
589-- occurrence).
580instance Reflex t => Alt (Event t) where
590instance Reflex t => Alt (Event t) where