set-extra 1.3 → 1.3.1
raw patch · 2 files changed
+17/−17 lines, 2 files
Files
- Data/Set/Extra.hs +16/−16
- set-extra.cabal +1/−1
Data/Set/Extra.hs view
@@ -1,5 +1,5 @@ module Data.Set.Extra- ( module Data.Set+ ( module Set , mapM , mapM_ , filterM@@ -24,14 +24,14 @@ , gFind ) where -import qualified Control.Monad as List (mapM, filterM, foldM)+import qualified Control.Monad as List (mapM, mapM_, filterM, foldM) import Control.Monad.State ()-import qualified Data.Map as Map-import Data.Set+import Data.Map as Map (Map, insertWith, empty)+import Data.Set as Set import Data.Set.ExtraG import qualified Data.List as List --import qualified Data.Maybe-import Prelude hiding (mapM, all, any, map, filter, null, concatMap, and, or)+import Prelude hiding (mapM, mapM_, unzip, all, any, map, filter, null, concatMap, and, or) --import qualified Prelude mapM :: (Monad m, Ord b) => (a -> m b) -> Set a -> m (Set b)@@ -44,23 +44,23 @@ filterM p s = List.filterM p (toList s) >>= return . fromList catMaybes :: Ord a => Set (Maybe a) -> Set a-catMaybes sm = fold (\ mx s -> maybe s (`insert` s) mx) empty sm+catMaybes sm = fold (\ mx s -> maybe s (`insert` s) mx) Set.empty sm -mapMaybe :: (a -> Maybe b) -> Set a -> Set b-mapMaybe f s = catMaybes (Data.Set.map f s)+mapMaybe :: (Ord a, Ord b) => (a -> Maybe b) -> Set a -> Set b+mapMaybe f s = catMaybes (Set.map f s) flatten :: Ord a => Set (Set a) -> Set a-flatten ss' = fold union empty ss'+flatten ss' = fold union Set.empty ss' --flatten = unions . toList concatMap :: (Ord a, Ord b) => (a -> Set b) -> Set a -> Set b-concatMap f s = flatten (Data.Set.map f s)+concatMap f s = flatten (Set.map f s) concatMapM :: (Monad m, Ord a, Ord b) => (a -> m (Set b)) -> Set a -> m (Set b) concatMapM f s = mapM f s >>= return . flatten any :: Ord a => (a -> Bool) -> Set a -> Bool-any f s = not . null . filter id . map f $ s+any f s = not . Set.null . Set.filter id . map f $ s {- anyM :: Monad m => (a -> m (Maybe Bool)) -> Set a -> m (Maybe Bool)@@ -71,7 +71,7 @@ -} all :: Ord a => (a -> Bool) -> Set a -> Bool-all f s = not . null . filter not . map f $ s+all f s = not . Set.null . Set.filter not . map f $ s or :: Set Bool -> Bool or = any id@@ -98,15 +98,15 @@ distrib lss rss = flatten $ map (\ rs -> (map (\ ls -> union rs ls) lss)) rss cartesianProduct :: (Ord a, Ord b) => Set a -> Set b -> Set (a, b)-cartesianProduct xs ys = flatten $ Data.Set.map (\ x -> Data.Set.map (\ y -> (x, y)) ys) xs+cartesianProduct xs ys = flatten $ Set.map (\ x -> Set.map (\ y -> (x, y)) ys) xs groupBy :: (Ord a, Ord b) => (a -> b) -> Set a -> Map.Map b (Set a) groupBy f xs = fold (\ x m -> Map.insertWith union (f x) (singleton x) m) Map.empty xs partitionM :: (Monad m, Ord a) => (a -> m Bool) -> Set a -> m (Set a, Set a) partitionM p xs =- List.foldM f (empty, empty) (toList xs)+ List.foldM f (Set.empty, Set.empty) (toList xs) where f (ts, fs) x = p x >>= \ flag -> return $ if flag then (insert x ts, fs) else (ts, insert x fs) -unzip :: Set (a, b) -> (Set a, Set b)-unzip s = fold (\ (l, r) (ls, rs) -> (Set.insert l ls, Set.insert r rs))+unzip :: (Ord a, Ord b) => Set (a, b) -> (Set a, Set b)+unzip s = Set.fold (\ (l, r) (ls, rs) -> (Set.insert l ls, Set.insert r rs)) (Set.empty, Set.empty) s
set-extra.cabal view
@@ -1,5 +1,5 @@ Name: set-extra-Version: 1.3+Version: 1.3.1 License: BSD3 License-File: COPYING Author: David Fox