on develop help sign in
Merge pull request #271 from alexfmpe/ae-option-functormaybe
e1ab868Ryan Trinkle
src/Reflex/FunctorMaybe.hs+12−1
@@ -1,3 +1,7 @@
1+{-# LANGUAGE CPP #-}
2+{-# LANGUAGE GeneralizedNewtypeDeriving #-}
3+{-# LANGUAGE StandaloneDeriving #-}
4+
1-- | This module defines the FunctorMaybe class, which extends Functors with the
5-- | This module defines the FunctorMaybe class, which extends Functors with the
2-- ability to delete values.
6-- ability to delete values.
3module Reflex.FunctorMaybe
7module Reflex.FunctorMaybe
@@ -9,12 +13,15 @@ import qualified Data.IntMap as IntMap
9import Data.Map (Map)
13import Data.Map (Map)
10import qualified Data.Map as Map
14import qualified Data.Map as Map
11import Data.Maybe
15import Data.Maybe
16+#if MIN_VERSION_base(4,9,0)
17+import Data.Semigroup (Option(..))
18+#endif
12
19
13--TODO: See if there's a better class in the standard libraries already
20--TODO: See if there's a better class in the standard libraries already
14
21
15-- | A class for values that combines filtering and mapping using 'Maybe'.
22-- | A class for values that combines filtering and mapping using 'Maybe'.
16-- Morally, @'FunctorMaybe' ~ KleisliFunctor 'Maybe'@. Also similar is the
23-- Morally, @'FunctorMaybe' ~ KleisliFunctor 'Maybe'@. Also similar is the
17−-- @Witherable@ typeclass, but it requires @Foldable f@ and @Traverable f@,
24+-- @Witherable@ typeclass, but it requires @'Foldable' f@ and @'Traversable' f@,
18-- and e.g. 'Event' is instance of neither.
25-- and e.g. 'Event' is instance of neither.
19--
26--
20-- A definition of 'fmapMaybe' must satisfy the following laws:
27-- A definition of 'fmapMaybe' must satisfy the following laws:
@@ -32,6 +39,10 @@ class FunctorMaybe f where
32instance FunctorMaybe Maybe where
39instance FunctorMaybe Maybe where
33 fmapMaybe = (=<<)
40 fmapMaybe = (=<<)
34
41
42+#if MIN_VERSION_base(4,9,0)
43+deriving instance FunctorMaybe Option
44+#endif
45+
35-- | @fmapMaybe = mapMaybe@
46-- | @fmapMaybe = mapMaybe@
36instance FunctorMaybe [] where
47instance FunctorMaybe [] where
37 fmapMaybe = mapMaybe
48 fmapMaybe = mapMaybe