Faster filterF, filterNotByte
[packages/old-time.git] / Data / FunctorM.hs
1 -----------------------------------------------------------------------------
2 -- |
3 -- Module : Data.FunctorM
4 -- Copyright : (c) The University of Glasgow 2005
5 -- License : BSD-style (see the file libraries/base/LICENSE)
6 --
7 -- Maintainer : libraries@haskell.org
8 -- Stability : provisional
9 -- Portability : portable
10 --
11 -- fmapM generalises fmap, just as mapM generalises map.
12 --
13 -- NOTE: This module is DEPRECATED.
14 -- The classes in "Data.Foldable" and "Data.Traversable" provide a
15 -- more general interface.
16 --
17 -----------------------------------------------------------------------------
18
19 module Data.FunctorM
20 {-# DEPRECATED "Use the more general Data.Foldable and Data.Traversable instead" #-}
21 (FunctorM(..)) where
22
23 import Prelude
24 import Data.Array
25
26 class FunctorM f where
27 fmapM :: Monad m => (a -> m b) -> f a -> m (f b)
28 fmapM_ :: Monad m => (a -> m b) -> f a -> m ()
29
30 fmapM_ f t = fmapM f t >> return ()
31
32 instance FunctorM [] where
33 fmapM = mapM
34 fmapM_ = mapM_
35
36 instance FunctorM Maybe where
37 fmapM _ Nothing = return Nothing
38 fmapM f (Just x) = f x >>= return . Just
39
40 fmapM_ _ Nothing = return ()
41 fmapM_ f (Just x) = f x >> return ()
42
43 instance Ix i => FunctorM (Array i) where
44 fmapM f a = do
45 a' <- sequence [ f e >>= return . (,) i | (i,e) <- assocs a]
46 return (array (bounds a) a')