on develop help sign in
Add convenience functions: filterLeft, filterRight
commit51519e94bfd30d46c7947b1e72490eabb5d24e1e authorSam Tay <sam.chong.tay@gmail.com> dateThu 31 Aug 2017, 13:41 (9 years ago) parent7216549
1 file changed+10
src/Reflex/Class.hs+10
src/Reflex/Class.hs+10
@@ -100,6 +100,8 @@ module Reflex.Class
100100 , FunctorMaybe (..)
101101 , fforMaybe
102102 , ffilter
103+ , filterLeft
104+ , filterRight
103105 -- * Miscellaneous convenience functions
104106 , ffor
105107 , MonadAdjust (..)
@@ -575,6 +577,14 @@ fforMaybe = flip fmapMaybe
575577ffilter :: FunctorMaybe f => (a -> Bool) -> f a -> f a
576578ffilter f = fmapMaybe $ \x -> if f x then Just x else Nothing
577579
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+
578588-- | Left-biased event union (prefers left event on simultaneous
579589-- occurrence).
580590instance Reflex t => Alt (Event t) where