Permalink
Browse files

Replace CanMap with Each

  • Loading branch information...
1 parent 95c8731 commit 024cf34a3690088238a6c28e5f0694162a1111a7 @snoyberg committed Sep 2, 2013
@@ -12,9 +12,6 @@ import qualified Data.ByteString as ByteString
import qualified Filesystem.Path.CurrentOS as FilePath
-instance CanMap ByteString ByteString Word8 Word8 where
- map = ByteString.map
-
instance CanConcatMap ByteString ByteString Word8 ByteString where
concatMap = ByteString.concatMap
@@ -8,10 +8,11 @@ module ClassyPrelude.Classes where
import CorePrelude
import qualified Data.List as List
+import qualified Control.Lens.Each as Each
+import qualified Control.Lens as Lens
-
-class CanMap ci co i o | ci -> i, co -> o, ci o -> co, co i -> ci where
- map :: (i -> o) -> ci -> co
+map :: Each.Each Lens.Mutator s t a b => (a -> b) -> s -> t
+map = Lens.over Each.each
class CanConcatMap ci co i o | ci -> i, co -> o, ci o -> co, co i -> ci where
concatMap :: (i -> o) -> ci -> co
@@ -12,9 +12,6 @@ import qualified Data.Foldable as Foldable
import qualified Data.HashMap.Strict as HashMap
-instance CanMap (HashMap k v1) (HashMap k v2) v1 v2 where
- map = HashMap.map
-
instance Hashable k => CanFilter (HashMap k v) (k, v) where
filter = HashMap.filterWithKey . curry
@@ -11,10 +11,6 @@ import ClassyPrelude.Classes
import qualified Data.HashSet as HashSet
import qualified Control.Monad as Monad
-
-instance (Eq b, Hashable b) => CanMap (HashSet a) (HashSet b) a b where
- map = HashSet.map
-
instance CanLength (HashSet x) Int where
length = HashSet.size
@@ -12,10 +12,6 @@ import qualified Data.ByteString as ByteString
import qualified Filesystem.Path.CurrentOS as FilePath
import qualified Data.ByteString.Lazy as LByteString
-
-instance CanMap LByteString LByteString Word8 Word8 where
- map = LByteString.map
-
instance CanConcatMap LByteString LByteString Word8 LByteString where
concatMap = LByteString.concatMap
@@ -13,10 +13,6 @@ import qualified Data.Text.Lazy.IO as LText
import qualified Data.Text.Lazy.Encoding as LText
import qualified Data.Text.Encoding.Error as Text
-
-instance CanMap LText LText Char Char where
- map = LText.map
-
instance CanConcatMap LText LText Char LText where
concatMap = LText.concatMap
@@ -11,10 +11,6 @@ import qualified Control.Monad as Monad
import qualified Data.Monoid as Monoid
import qualified Data.Set as Set
-
-instance CanMap [a] [b] a b where
- map = List.map
-
instance CanConcatMap [a] [b] a [b] where
concatMap = List.concatMap
@@ -11,10 +11,6 @@ import ClassyPrelude.Classes
import qualified Data.Foldable as Foldable
import qualified Data.Map as Map
-
-instance CanMap (Map k v1) (Map k v2) v1 v2 where
- map = Map.map
-
instance Ord k => CanFilter (Map k v) (k, v) where
filter = Map.filterWithKey . curry
@@ -11,10 +11,6 @@ import qualified Control.Monad as Monad
import qualified Data.Foldable as Foldable
import qualified Data.Traversable as Traversable
-
-instance CanMap (Maybe a) (Maybe b) a b where
- map = Monad.fmap
-
instance CanConcatMap (Maybe a) (Maybe b) a (Maybe b) where
concatMap = (Monad.=<<)
@@ -15,10 +15,6 @@ import qualified Data.Traversable as Traversable
import qualified Data.Sequence as Seq
import Data.Sequence (Seq, (<|), (|>), ViewL(..), viewl, ViewR(..), viewr)
-
-instance CanMap (Seq a) (Seq b) a b where
- map = Monad.fmap
-
instance CanConcatMap (Seq a) (Seq b) a (Seq b) where
concatMap = (Monad.=<<)
@@ -12,10 +12,6 @@ import qualified Control.Monad as Monad
import qualified Data.Foldable as Foldable
import qualified Data.Set as Set
-
-instance (Ord a, Ord b) => CanMap (Set a) (Set b) a b where
- map = Set.map
-
instance Ord a => CanFilter (Set a) a where
filter = Set.filter
@@ -13,10 +13,6 @@ import qualified Data.Text.Encoding as Text
import qualified Data.Text.Encoding.Error as Text
import qualified Data.Text.IO as Text
-
-instance CanMap Text Text Char Char where
- map = Text.map
-
instance CanConcatMap Text Text Char Text where
concatMap = Text.concatMap
@@ -10,9 +10,6 @@ import CorePrelude
import ClassyPrelude.Classes
import qualified Data.Vector.Unboxed as UVector
-instance (Unbox a, Unbox b) => CanMap (UVector a) (UVector b) a b where
- map = UVector.map
-
instance (Unbox a, Unbox b) => CanConcatMap (UVector a) (UVector b) a (UVector b) where
concatMap = UVector.concatMap
@@ -11,10 +11,6 @@ import ClassyPrelude.Classes
import qualified Data.Foldable as Foldable
import qualified Data.Vector as Vector
-
-instance CanMap (Vector a) (Vector b) a b where
- map = Vector.map
-
instance CanConcatMap (Vector a) (Vector b) a (Vector b) where
concatMap = Vector.concatMap
@@ -17,6 +17,8 @@ import Data.Maybe (isJust)
import Data.Functor.Identity (runIdentity)
import Control.Concurrent (throwTo, threadDelay, forkIO)
import Control.Exception (throw)
+import qualified Control.Lens as Lens
+import qualified Control.Lens.Each as Each
dictionaryProps
:: ( CanInsertVal a Int Char
@@ -42,6 +44,7 @@ dictionaryProps dummy = do
prop "lookup k (delete k c) == Nothing" $ \k c ->
lookup k (delete k c`asTypeOf` dummy) == Nothing
+{-
mapProps :: ( CanPack a i
, CanPack b j
, Eq a
@@ -59,6 +62,7 @@ mapProps :: ( CanPack a i
-> (i -> j)
-> (j -> k)
-> Spec
+ -}
mapProps dummy f g = do
prop "map f c == pack (map f (unpack c))" $ \c ->
map f (c `asTypeOf` dummy) == pack (map f (unpack c))
@@ -74,7 +78,7 @@ concatMapProps :: ( CanPack a i
, Eq b
, Show b
, Arbitrary b
- , CanMap a b i j
+ , Each.Each Lens.Mutator a b i j
, CanConcatMap a b i js
)
=> a
@@ -274,8 +278,8 @@ main = hspec $ do
describe "list" $ mapProps (undefined :: [Int]) (+ 1) (+ 2)
describe "Data.Vector" $ mapProps (undefined :: Vector Int) (+ 1) (+ 2)
describe "Data.Vector.Unboxed" $ mapProps (undefined :: UVector Int) (+ 1) (+ 2)
- describe "Data.Set" $ mapProps (undefined :: Set Int) (+ 1) (+ 2)
- describe "Data.HashSet" $ mapProps (undefined :: HashSet Int) (+ 1) (+ 2)
+ --describe "Data.Set" $ mapProps (undefined :: Set Int) (+ 1) (+ 2)
+ --describe "Data.HashSet" $ mapProps (undefined :: HashSet Int) (+ 1) (+ 2)
describe "Data.ByteString" $ mapProps (undefined :: ByteString) (+ 1) (+ 2)
describe "Data.ByteString.Lazy" $ mapProps (undefined :: LByteString) (+ 1) (+ 2)
describe "Data.Text" $ mapProps (undefined :: Text) succ succ

0 comments on commit 024cf34

Please sign in to comment.