on ae@dev-script help sign in
reflex/src/Reflex/FunctorMaybe.hs
47 lines 1.2 kB history raw
1{-# LANGUAGE CPP #-}
2#if MIN_VERSION_base(4,9,0)
3{-# LANGUAGE GeneralizedNewtypeDeriving #-}
4{-# LANGUAGE StandaloneDeriving #-}
5#endif
7-- |
8-- Module:
9-- Reflex.FunctorMaybe
10-- Description:
11-- This module defines the FunctorMaybe class, which extends Functors with the
12-- ability to delete values.
13module Reflex.FunctorMaybe
14 ( FunctorMaybe (..)
15 ) where
17import Data.IntMap (IntMap)
18import Data.Map (Map)
19#if MIN_VERSION_base(4,9,0)
20import Data.Semigroup (Option(..))
21#endif
22import Data.Witherable
24--TODO: See if there's a better class in the standard libraries already
26-- | A class for values that combines filtering and mapping using 'Maybe'.
27-- Morally, @'FunctorMaybe' ~ KleisliFunctor 'Maybe'@.
28{-# DEPRECATED FunctorMaybe "Use 'Filterable' from Data.Witherable instead" #-}
29class FunctorMaybe f where
30 -- | Combined mapping and filtering function.
31 fmapMaybe :: (a -> Maybe b) -> f a -> f b
33instance FunctorMaybe Maybe where
34 fmapMaybe = mapMaybe
36#if MIN_VERSION_base(4,9,0)
37deriving instance FunctorMaybe Option
38#endif
40instance FunctorMaybe [] where
41 fmapMaybe = mapMaybe
43instance FunctorMaybe (Map k) where
44 fmapMaybe = mapMaybe
46instance FunctorMaybe IntMap where
47 fmapMaybe = mapMaybe