2{-# LANGUAGE GeneralizedNewtypeDeriving #-}
3{-# LANGUAGE StandaloneDeriving #-}
5-- | This module defines the FunctorMaybe class, which extends Functors with the
6-- ability to delete values.
7module Reflex.FunctorMaybe
11import Data.IntMap (IntMap)
12import qualified Data.IntMap as IntMap
14import qualified Data.Map as Map
16#if MIN_VERSION_base(4,9,0)
17import Data.Semigroup (Option(..))
20--TODO: See if there's a better class in the standard libraries already
22-- | A class for values that combines filtering and mapping using 'Maybe'.
23-- Morally, @'FunctorMaybe' ~ KleisliFunctor 'Maybe'@. Also similar is the
24-- @Witherable@ typeclass, but it requires @'Foldable' f@ and @'Traversable' f@,
25-- and e.g. 'Event' is instance of neither.
27-- A definition of 'fmapMaybe' must satisfy the following laws:
30-- @'fmapMaybe' 'Just' ≡ 'id'@
33-- @'fmapMaybe' (f <=< g) ≡ 'fmapMaybe' f . 'fmapMaybe' g@
34class FunctorMaybe f where
35 -- | Combined mapping and filtering function.
36 fmapMaybe :: (a -> Maybe b) -> f a -> f b
38-- | @fmapMaybe = (=<<)
39instance FunctorMaybe Maybe where
42#if MIN_VERSION_base(4,9,0)
43deriving instance FunctorMaybe Option
46-- | @fmapMaybe = mapMaybe@
47instance FunctorMaybe [] where
50instance FunctorMaybe (Map k) where
51 fmapMaybe = Map.mapMaybe
53instance FunctorMaybe IntMap where
54 fmapMaybe = IntMap.mapMaybe
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list