on develop help sign in
Add Functor superclass for FunctorMaybe; docs
61c2268Lennart Spitzner
src/Reflex/Class.hs+14−1
@@ -409,8 +409,21 @@ instance (Reflex t, Semigroup a) => Semigroup (Behavior t a) where
409#endif
409#endif
410
410
411--TODO: See if there's a better class in the standard libraries already
411--TODO: See if there's a better class in the standard libraries already
412+
412-- | A class for values that combines filtering and mapping using 'Maybe'.
413-- | A class for values that combines filtering and mapping using 'Maybe'.
414+-- Morally, @'FunctorMaybe' ~ KleisliFunctor 'Maybe'@. Also similar is the
415+-- @Witherable@ typeclass, but it requires @Foldable f@ and @Traverable f@,
416+-- and e.g. 'Event' is instance of neither.
417+--
418+-- A definition of 'fmapMaybe' must satisfy the following laws:
419+--
420+-- [/identity/]
421+-- @'fmapMaybe' 'Just' ≡ 'id'@
422+--
423+-- [/composition/]
424+-- @'fmapMaybe' (f <=< g) ≡ 'fmapMaybe' f . 'fmapMaybe' g@
425+
413−class FunctorMaybe f where
426+class Functor f => FunctorMaybe f where
414 -- | Combined mapping and filtering function.
427 -- | Combined mapping and filtering function.
415 fmapMaybe :: (a -> Maybe b) -> f a -> f b
428 fmapMaybe :: (a -> Maybe b) -> f a -> f b
416
429