@@ -137,8 +137,10 @@ module Reflex.Class
137137 -- * Unsafe functions
138138 , unsafeDynamic
139139 , unsafeMapIncremental
140− -- * 'FunctorMaybe'
141− , FunctorMaybe (..)
140+ -- * 'Filterable' convenience functions
141+ , FunctorMaybe -- fmapMaybe is purposely not exported from deprecated 'FunctorMaybe' and the new alias is exported instead
142+ , mapMaybe -- Re-exported for convenience
143+ , fmapMaybe
142144 , fforMaybe
143145 , ffilter
144146 , filterLeft
@@ -152,6 +154,7 @@ module Reflex.Class
152154 , switchPromptOnly
153155 -- * "Cheap" functions
154156 , fmapMaybeCheap
157+ , mapMaybeCheap
155158 , fmapCheap
156159 , fforCheap
157160 , fforMaybeCheap
@@ -195,7 +198,10 @@ import qualified Data.Some as Some
195198import Data.String
196199import Data.These
197200import Data.Type.Coercion
198−import Reflex.FunctorMaybe
201+import Data.Witherable (Filterable(..))
202+import qualified Data.Witherable as W
203+import Reflex.FunctorMaybe (FunctorMaybe)
204+import qualified Reflex.FunctorMaybe
199205import Reflex.Patch
200206import qualified Reflex.Patch.MapWithMove as PatchMapWithMove
201207
@@ -389,8 +395,8 @@ mapAccumMaybeMIncremental f z e = do
389395 return $ case result of
390396 (Nothing, Nothing) -> Nothing
391397 _ -> Just result
392− d' <- holdIncremental z $ fmapMaybe fst e'
393− return (d', fmapMaybe snd e')
398+ d' <- holdIncremental z $ mapMaybe fst e'
399+ return (d', mapMaybe snd e')
394400
395401slowHeadE :: (Reflex t, MonadHold t m, MonadFix m) => Event t a -> m (Event t a)
396402slowHeadE e = do
@@ -400,14 +406,14 @@ slowHeadE e = do
400406
401407-- | An 'EventSelector' allows you to efficiently 'select' an 'Event' based on a
402408-- key. This is much more efficient than filtering for each key with
403−-- 'fmapMaybe'.
409+-- 'mapMaybe'.
404410newtype EventSelector t k = EventSelector
405411 { -- | Retrieve the 'Event' for the given key. The type of the 'Event' is
406412 -- determined by the type of the key, so this can be used to fan-out
407413 -- 'Event's whose sub-'Event's have different types.
408414 --
409415 -- Using 'EventSelector's and the 'fan' primitive is far more efficient than
410− -- (but equivalent to) using 'fmapMaybe' to select only the relevant
416+ -- (but equivalent to) using 'mapMaybe' to select only the relevant
411417 -- occurrences of an 'Event'.
412418 select :: forall a. k a -> Event t a
413419 }
@@ -551,22 +557,25 @@ instance (Reflex t, Semigroup a) => Semigroup (Behavior t a) where
551557 times1p n = fmap $ times1p n
552558#endif
553559
554−-- | Flipped version of 'fmapMaybe'.
555−fforMaybe :: FunctorMaybe f => f a -> (a -> Maybe b) -> f b
556−fforMaybe = flip fmapMaybe
560+-- | Alias for 'mapMaybe'
561+fmapMaybe :: Filterable f => (a -> Maybe b) -> f a -> f b
562+fmapMaybe = mapMaybe
563+
564+-- | Flipped version of 'mapMaybe'.
565+fforMaybe :: Filterable f => f a -> (a -> Maybe b) -> f b
566+fforMaybe = flip mapMaybe
557567
558568-- | Filter 'f a' using the provided predicate.
559−-- Relies on 'fforMaybe'.
560−ffilter :: FunctorMaybe f => (a -> Bool) -> f a -> f a
561−ffilter f = fmapMaybe $ \x -> if f x then Just x else Nothing
569+ffilter :: Filterable f => (a -> Bool) -> f a -> f a
570+ffilter = W.filter
562571
563572-- | Filter 'Left's from 'f (Either a b)' into 'a'.
564−filterLeft :: FunctorMaybe f => f (Either a b) -> f a
565−filterLeft = fmapMaybe (either Just (const Nothing))
573+filterLeft :: Filterable f => f (Either a b) -> f a
574+filterLeft = mapMaybe (either Just (const Nothing))
566575
567576-- | Filter 'Right's from 'f (Either a b)' into 'b'.
568−filterRight :: FunctorMaybe f => f (Either a b) -> f b
569−filterRight = fmapMaybe (either (const Nothing) Just)
577+filterRight :: Filterable f => f (Either a b) -> f b
578+filterRight = mapMaybe (either (const Nothing) Just)
570579
571580-- | Left-biased event union (prefers left event on simultaneous
572581-- occurrence).
@@ -584,13 +593,18 @@ instance Reflex t => Bind (Event t) where
584593
585594instance Reflex t => Functor (Event t) where
586595 {-# INLINE fmap #-}
587− fmap f = fmapMaybe $ Just . f
596+ fmap f = mapMaybe $ Just . f
588597 {-# INLINE (<$) #-}
589598 x <$ e = fmapCheap (const x) e
590599
600+-- TODO Remove this instance
591601instance Reflex t => FunctorMaybe (Event t) where
592602 {-# INLINE fmapMaybe #-}
593− fmapMaybe f = push $ return . f
603+ fmapMaybe = mapMaybe
604+
605+instance Reflex t => Filterable (Event t) where
606+ {-# INLINE mapMaybe #-}
607+ mapMaybe f = push $ return . f
594608
595609-- | Never: @'zero' = 'never'@.
596610instance Reflex t => Plus (Event t) where
@@ -808,7 +822,7 @@ fanEither :: Reflex t => Event t (Either a b) -> (Event t a, Event t b)
808822fanEither e =
809823 let justLeft = either Just (const Nothing)
810824 justRight = either (const Nothing) Just
811− in (fmapMaybe justLeft e, fmapMaybe justRight e)
825+ in (mapMaybe justLeft e, mapMaybe justRight e)
812826
813827-- | Split the event into separate events for 'This' and 'That' values,
814828-- allowing them to fire simultaneously when the input value is 'These'.
@@ -820,7 +834,7 @@ fanThese e =
820834 that (That y) = Just y
821835 that (These _ y) = Just y
822836 that _ = Nothing
823− in (fmapMaybe this e, fmapMaybe that e)
837+ in (mapMaybe this e, mapMaybe that e)
824838
825839-- | Split the event into an 'EventSelector' that allows efficient selection of
826840-- the individual 'Event's.
@@ -1004,7 +1018,7 @@ difference = alignEventWithMaybe $ \case
10041018-- | Zips two values by taking the union of their shapes and combining with the provided function.
10051019-- 'Nothing' values are dropped.
10061020alignEventWithMaybe :: Reflex t => (These a b -> Maybe c) -> Event t a -> Event t b -> Event t c
1007−alignEventWithMaybe f ea eb = fmapMaybe (f <=< dmapToThese) $
1021+alignEventWithMaybe f ea eb = mapMaybe (f <=< dmapToThese) $
10081022 merge $ DMap.fromList [LeftTag :=> ea, RightTag :=> eb]
10091023
10101024-- | Produces an 'Event' that fires only when the input event fires with a 'DSum' key that
@@ -1174,8 +1188,8 @@ mapAccumMaybeMDyn f z e = do
11741188 return $ case result of
11751189 (Nothing, Nothing) -> Nothing
11761190 _ -> Just result
1177− d' <- holdDyn z $ fmapMaybe fst e'
1178− return (d', fmapMaybe snd e')
1191+ d' <- holdDyn z $ mapMaybe fst e'
1192+ return (d', mapMaybe snd e')
11791193
11801194-- | Accumulate a 'Behavior' by folding occurrences of an 'Event'
11811195-- with the provided function.
@@ -1263,8 +1277,8 @@ mapAccumMaybeMB f z e = do
12631277 return $ case result of
12641278 (Nothing, Nothing) -> Nothing
12651279 _ -> Just result
1266− d' <- hold z $ fmapMaybe fst e'
1267− return (d', fmapMaybe snd e')
1280+ d' <- hold z $ mapMaybe fst e'
1281+ return (d', mapMaybe snd e')
12681282
12691283-- | Accumulate occurrences of an 'Event', producing an output occurrence each
12701284-- time. Discard the underlying 'Accumulator'.
@@ -1413,15 +1427,21 @@ infixl 4 <@
14131427pushAlwaysCheap :: Reflex t => (a -> PushM t b) -> Event t a -> Event t b
14141428pushAlwaysCheap f = pushCheap (fmap Just . f)
14151429
1416−-- | A "cheap" version of 'fmapMaybe'. See the performance note on 'pushCheap'.
1430+-- | A "cheap" version of 'mapMaybe'. See the performance note on 'pushCheap'.
1431+{-# INLINE mapMaybeCheap #-}
1432+mapMaybeCheap :: Reflex t => (a -> Maybe b) -> Event t a -> Event t b
1433+mapMaybeCheap f = pushCheap $ return . f
1434+
1435+-- | An alias for 'mapMaybeCheap'
14171436{-# INLINE fmapMaybeCheap #-}
14181437fmapMaybeCheap :: Reflex t => (a -> Maybe b) -> Event t a -> Event t b
1419−fmapMaybeCheap f = pushCheap $ return . f
1438+fmapMaybeCheap = mapMaybeCheap
1439+
14201440
14211441-- | A "cheap" version of 'fforMaybe'. See the performance note on 'pushCheap'.
14221442{-# INLINE fforMaybeCheap #-}
14231443fforMaybeCheap :: Reflex t => Event t a -> (a -> Maybe b) -> Event t b
1424−fforMaybeCheap = flip fmapMaybeCheap
1444+fforMaybeCheap = flip mapMaybeCheap
14251445
14261446-- | A "cheap" version of 'ffor'. See the performance note on 'pushCheap'.
14271447{-# INLINE fforCheap #-}