~ubuntu-branches/ubuntu/wily/agda/wily-proposed

« back to all changes in this revision

Viewing changes to src/full/Agda/Utils/Map.hs

  • Committer: Package Import Robot
  • Author(s): Iain Lane
  • Date: 2014-08-05 06:38:12 UTC
  • mfrom: (1.1.6)
  • Revision ID: package-import@ubuntu.com-20140805063812-io8e77niomivhd49
Tags: 2.4.0.2-1
* [6e140ac] Imported Upstream version 2.4.0.2
* [2049fc8] Update Build-Depends to match control
* [93dc4d4] Install the new primitives
* [e48f40f] Fix typo dev→doc

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
import Data.Map as Map
8
8
import Data.Traversable
9
9
 
10
 
import Agda.Utils.Monad
11
10
import Agda.Utils.Tuple
12
11
 
13
12
#include "../undefined.h"
14
13
import Agda.Utils.Impossible
15
14
 
 
15
-- * Monadic map operations
 
16
---------------------------------------------------------------------------
 
17
 
16
18
data EitherOrBoth a b = L a | B a b | R b
17
19
 
18
20
-- | Not very efficient (goes via a list), but it'll do.
36
38
            return $ insert k z m
37
39
        Nothing -> return $ insert k x m
38
40
 
 
41
-- * Non-monadic map operations
 
42
---------------------------------------------------------------------------
 
43
 
 
44
-- | Big conjunction over a map.
 
45
allWithKey :: (k -> a -> Bool) -> Map k a -> Bool
 
46
allWithKey f = Map.foldrWithKey (\ k a b -> f k a && b) True
 
47
 
39
48
-- | Filter a map based on the keys.
40
49
filterKeys :: Ord k => (k -> Bool) -> Map k a -> Map k a
41
50
filterKeys p = filterWithKey (const . p)