data-diverse 0.5.0.0 → 0.6.0.0
raw patch · 7 files changed
+2/−447 lines, 7 filesdep −lensdep ~data-diversePVP ok
version bump matches the API change (PVP)
Dependencies removed: lens
Dependency ranges changed: data-diverse
API changes (from Hackage documentation)
- Data.Diverse.Many: _Many :: IsMany t xs a => Iso' (Many xs) (t xs a)
- Data.Diverse.Many: _Many' :: IsMany Tagged xs a => Iso' (Many xs) a
- Data.Diverse.Many: item :: forall x xs. UniqueMember x xs => Lens' (Many xs) x
- Data.Diverse.Many: item' :: forall x y xs. UniqueMember x xs => Lens (Many xs) (Many (Replace x y xs)) x y
- Data.Diverse.Many: itemL :: forall l xs x proxy. (UniqueLabelMember l xs, x ~ KindAtLabel l xs) => proxy l -> Lens' (Many xs) x
- Data.Diverse.Many: itemL' :: forall l y xs x proxy. (UniqueLabelMember l xs, x ~ KindAtLabel l xs) => proxy l -> Lens (Many xs) (Many (Replace x y xs)) x y
- Data.Diverse.Many: itemN :: forall n x xs proxy. MemberAt n x xs => proxy n -> Lens' (Many xs) x
- Data.Diverse.Many: itemN' :: forall n x y xs proxy. MemberAt n x xs => proxy n -> Lens (Many xs) (Many (ReplaceIndex n y xs)) x y
- Data.Diverse.Many: project :: forall smaller larger. (Select smaller larger, Amend smaller larger) => Lens' (Many larger) (Many smaller)
- Data.Diverse.Many: project' :: forall smaller smaller' larger zipped. (Select smaller larger, Amend' smaller smaller' larger zipped) => Lens (Many larger) (Many (Replaces smaller smaller' larger)) (Many smaller) (Many smaller')
- Data.Diverse.Many: projectL :: forall ls smaller larger proxy. (Select smaller larger, Amend smaller larger, smaller ~ KindsAtLabels ls larger, IsDistinct ls, UniqueLabels ls larger) => proxy ls -> Lens' (Many larger) (Many smaller)
- Data.Diverse.Many: projectL' :: forall ls smaller smaller' larger proxy zipped. (Select smaller larger, Amend' smaller smaller' larger zipped, smaller ~ KindsAtLabels ls larger, IsDistinct ls, UniqueLabels ls larger) => proxy ls -> Lens (Many larger) (Many (Replaces smaller smaller' larger)) (Many smaller) (Many smaller')
- Data.Diverse.Many: projectN :: forall ns smaller larger proxy. (SelectN ns smaller larger, AmendN ns smaller larger) => proxy ns -> Lens' (Many larger) (Many smaller)
- Data.Diverse.Many: projectN' :: forall ns smaller smaller' larger proxy zipped. (SelectN ns smaller larger, AmendN' ns smaller smaller' larger zipped) => proxy ns -> Lens (Many larger) (Many (ReplacesIndex ns smaller' larger)) (Many smaller) (Many smaller')
- Data.Diverse.Many.Internal: _Many :: IsMany t xs a => Iso' (Many xs) (t xs a)
- Data.Diverse.Many.Internal: _Many' :: IsMany Tagged xs a => Iso' (Many xs) a
- Data.Diverse.Many.Internal: item :: forall x xs. UniqueMember x xs => Lens' (Many xs) x
- Data.Diverse.Many.Internal: item' :: forall x y xs. UniqueMember x xs => Lens (Many xs) (Many (Replace x y xs)) x y
- Data.Diverse.Many.Internal: itemL :: forall l xs x proxy. (UniqueLabelMember l xs, x ~ KindAtLabel l xs) => proxy l -> Lens' (Many xs) x
- Data.Diverse.Many.Internal: itemL' :: forall l y xs x proxy. (UniqueLabelMember l xs, x ~ KindAtLabel l xs) => proxy l -> Lens (Many xs) (Many (Replace x y xs)) x y
- Data.Diverse.Many.Internal: itemN :: forall n x xs proxy. MemberAt n x xs => proxy n -> Lens' (Many xs) x
- Data.Diverse.Many.Internal: itemN' :: forall n x y xs proxy. MemberAt n x xs => proxy n -> Lens (Many xs) (Many (ReplaceIndex n y xs)) x y
- Data.Diverse.Many.Internal: project :: forall smaller larger. (Select smaller larger, Amend smaller larger) => Lens' (Many larger) (Many smaller)
- Data.Diverse.Many.Internal: project' :: forall smaller smaller' larger zipped. (Select smaller larger, Amend' smaller smaller' larger zipped) => Lens (Many larger) (Many (Replaces smaller smaller' larger)) (Many smaller) (Many smaller')
- Data.Diverse.Many.Internal: projectL :: forall ls smaller larger proxy. (Select smaller larger, Amend smaller larger, smaller ~ KindsAtLabels ls larger, IsDistinct ls, UniqueLabels ls larger) => proxy ls -> Lens' (Many larger) (Many smaller)
- Data.Diverse.Many.Internal: projectL' :: forall ls smaller smaller' larger proxy zipped. (Select smaller larger, Amend' smaller smaller' larger zipped, smaller ~ KindsAtLabels ls larger, IsDistinct ls, UniqueLabels ls larger) => proxy ls -> Lens (Many larger) (Many (Replaces smaller smaller' larger)) (Many smaller) (Many smaller')
- Data.Diverse.Many.Internal: projectN :: forall ns smaller larger proxy. (SelectN ns smaller larger, AmendN ns smaller larger) => proxy ns -> Lens' (Many larger) (Many smaller)
- Data.Diverse.Many.Internal: projectN' :: forall ns smaller smaller' larger proxy zipped. (SelectN ns smaller larger, AmendN' ns smaller smaller' larger zipped) => proxy ns -> Lens (Many larger) (Many (ReplacesIndex ns smaller' larger)) (Many smaller) (Many smaller')
- Data.Diverse.Which: facet :: forall x xs. (UniqueMember x xs) => Prism' (Which xs) x
- Data.Diverse.Which: facetL :: forall l xs x proxy. (UniqueLabelMember l xs, x ~ KindAtLabel l xs) => proxy l -> Prism' (Which xs) x
- Data.Diverse.Which: facetN :: forall n xs x proxy. (MemberAt n x xs) => proxy n -> Prism' (Which xs) x
- Data.Diverse.Which: inject :: forall branch tree. (Diversify tree branch, Reinterpret branch tree) => Prism' (Which tree) (Which branch)
- Data.Diverse.Which: injectL :: forall ls branch tree proxy. (Diversify tree branch, Reinterpret branch tree, branch ~ KindsAtLabels ls tree, UniqueLabels ls tree, IsDistinct ls) => proxy ls -> Prism' (Which tree) (Which branch)
- Data.Diverse.Which: injectN :: forall indices branch tree proxy. (DiversifyN indices tree branch, ReinterpretN indices branch tree) => proxy indices -> Prism' (Which tree) (Which branch)
- Data.Diverse.Which.Internal: facet :: forall x xs. (UniqueMember x xs) => Prism' (Which xs) x
- Data.Diverse.Which.Internal: facetL :: forall l xs x proxy. (UniqueLabelMember l xs, x ~ KindAtLabel l xs) => proxy l -> Prism' (Which xs) x
- Data.Diverse.Which.Internal: facetN :: forall n xs x proxy. (MemberAt n x xs) => proxy n -> Prism' (Which xs) x
- Data.Diverse.Which.Internal: inject :: forall branch tree. (Diversify tree branch, Reinterpret branch tree) => Prism' (Which tree) (Which branch)
- Data.Diverse.Which.Internal: injectL :: forall ls branch tree proxy. (Diversify tree branch, Reinterpret branch tree, branch ~ KindsAtLabels ls tree, UniqueLabels ls tree, IsDistinct ls) => proxy ls -> Prism' (Which tree) (Which branch)
- Data.Diverse.Which.Internal: injectN :: forall indices branch tree proxy. (DiversifyN indices tree branch, ReinterpretN indices branch tree) => proxy indices -> Prism' (Which tree) (Which branch)
Files
- data-diverse.cabal +2/−4
- src/Data/Diverse/Many.hs +0/−16
- src/Data/Diverse/Many/Internal.hs +0/−178
- src/Data/Diverse/Which.hs +0/−8
- src/Data/Diverse/Which/Internal.hs +0/−117
- test/Data/Diverse/ManySpec.hs +0/−86
- test/Data/Diverse/WhichSpec.hs +0/−38
data-diverse.cabal view
@@ -1,5 +1,5 @@ name: data-diverse-version: 0.5.0.0+version: 0.6.0.0 synopsis: Extensible records and polymorphic variants. description: "Data.Diverse.Many" is an extensible record for any size encoded efficiently as (Int, Map Int Any). "Data.Diverse.Which" is a polymorphic variant of possibilities encoded as (Int, Any).@@ -36,7 +36,6 @@ build-depends: base >= 4.7 && < 5 , containers >= 0.5 && < 0.6 , ghc-prim >= 0.5 && < 1- , lens >= 4 && < 5 , tagged >= 0.8.5 && < 1 ghc-options: -Wall default-language: Haskell2010@@ -49,9 +48,8 @@ Data.Diverse.TypeSpec Data.Diverse.WhichSpec build-depends: base- , data-diverse >= 0.2.1 && < 1+ , data-diverse , hspec >= 2 && < 3- , lens >= 4 && < 5 , tagged >= 0.8.5 && < 1 ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall default-language: Haskell2010
src/Data/Diverse/Many.hs view
@@ -7,8 +7,6 @@ , IsMany(..) , fromMany' , toMany'- , _Many- , _Many' -- * Construction , nil@@ -38,13 +36,6 @@ , replaceL' , replaceN , replaceN'- -- ** Lens for a single field- , item- , item'- , itemL- , itemL'- , itemN- , itemN' -- * Multiple fields -- ** Getter for multiple fields@@ -64,13 +55,6 @@ , amendN , AmendN' , amendN'- -- ** Lens for multiple fields- , project- , project'- , projectL- , projectL'- , projectN- , projectN' -- * Destruction -- ** By type
src/Data/Diverse/Many/Internal.hs view
@@ -23,8 +23,6 @@ , IsMany(..) , fromMany' , toMany'- , _Many- , _Many' -- * Construction , nil@@ -54,13 +52,6 @@ , replaceL' , replaceN , replaceN'- -- ** Lens for a single field- , item- , item'- , itemL- , itemL'- , itemN- , itemN' -- * Multiple fields -- ** Getter for multiple fields@@ -80,13 +71,6 @@ , amendN , AmendN' , amendN'- -- ** Lens for multiple fields- , project- , project'- , projectL- , projectL'- , projectN- , projectN' -- * Destruction -- ** By type@@ -98,7 +82,6 @@ ) where import Control.Applicative-import Control.Lens import Data.Bool import Data.Diverse.AFoldable import Data.Diverse.Case@@ -203,16 +186,6 @@ fromMany' :: IsMany Tagged xs a => Many xs -> a fromMany' = unTagged . fromMany --- | @_Many = iso fromMany toMany@-_Many :: IsMany t xs a => Iso' (Many xs) (t xs a)-_Many = iso fromMany toMany-{-# INLINE _Many #-}---- | @_Many' = iso fromMany' toMany'@-_Many' :: IsMany Tagged xs a => Iso' (Many xs) a-_Many' = iso fromMany' toMany'-{-# INLINE _Many' #-}- -- | These instances add about 7 seconds to the compile time! instance IsMany Tagged '[] () where toMany _ = nil@@ -536,64 +509,6 @@ ----------------------------------------------------------------------- --- | 'fetch' ('view' 'item') and 'replace' ('set' 'item') in 'Lens'' form.------ @--- let x = (5 :: Int) './' False './' \'X' './' Just \'O' './' 'nil'--- x '^.' 'item' \@Int \`shouldBe` 5--- (x '&' 'item' \@Int .~ 6) \`shouldBe` (6 :: Int) './' False './' \'X' './' Just \'O' './' 'nil'--- @-item :: forall x xs. UniqueMember x xs => Lens' (Many xs) x-item = lens fetch replace-{-# INLINE item #-}---- | Polymorphic version of 'item'-item' :: forall x y xs. UniqueMember x xs => Lens (Many xs) (Many (Replace x y xs)) x y-item' = lens fetch (replace' @x @y Proxy)-{-# INLINE item' #-}----- | 'fetchL' ('view' 'itemL') and 'replaceL' ('set' 'itemL') in 'Lens'' form.------ @--- let x = (5 :: Int) './' Tagged \@Foo False './' Tagged \@Bar \'X' './' 'nil'--- x '^.' 'itemL' \@Foo Proxy \`shouldBe` Tagged \@Foo False--- (x '&' 'itemL' \@Foo Proxy '.~' Tagged \@Foo True) \`shouldBe` (5 :: Int) './' Tagged \@Foo True './' Tagged \@Bar \'X' './' 'nil'--- @-itemL :: forall l xs x proxy. (UniqueLabelMember l xs, x ~ KindAtLabel l xs) => proxy l -> Lens' (Many xs) x-itemL p = lens (fetchL p) (replaceL p)-{-# INLINE itemL #-}---- | Polymorphic version of 'itemL'------ @--- let x = (5 :: Int) './' Tagged @Foo False './' Tagged \@Bar \'X' './' 'nil'--- (x '&' itemL' \@Foo Proxy '.~' \"foo") \`shouldBe` (5 :: Int) './' \"foo" './' Tagged \@Bar \'X' './' 'nil'--- @-itemL' :: forall l y xs x proxy. (UniqueLabelMember l xs, x ~ KindAtLabel l xs) => proxy l -> Lens (Many xs) (Many (Replace x y xs)) x y-itemL' p = lens (fetchL p) (replaceL' p)-{-# INLINE itemL' #-}----- | 'fetchN' ('view' 'item') and 'replaceN' ('set' 'item') in 'Lens'' form.------ @--- let x = (5 :: Int) './' False './' \'X' './' Just \'O' './' (6 :: Int) './' Just \'A' ./ nil--- x '^.' 'itemN' (Proxy \@0) \`shouldBe` 5--- (x '&' 'itemN' (Proxy @0) '.~' 6) \`shouldBe` (6 :: Int) './' False './' \'X' './' Just \'O' './' (6 :: Int) './' Just \'A' './' 'nil'--- @-itemN :: forall n x xs proxy. MemberAt n x xs => proxy n -> Lens' (Many xs) x-itemN p = lens (fetchN p) (replaceN p)-{-# INLINE itemN #-}----- | Polymorphic version of 'itemN'-itemN' :: forall n x y xs proxy. MemberAt n x xs => proxy n -> Lens (Many xs) (Many (ReplaceIndex n y xs)) x y-itemN' p = lens (fetchN p) (replaceN' @n @x @y p)-{-# INLINE itemN' #-}-------------------------------------------------------------------------- -- | Internal function for construction - do not expose! fromList' :: Ord k => [(k, WrappedAny)] -> M.Map k Any fromList' xs = M.fromList (coerce xs)@@ -1031,99 +946,6 @@ caseAny (CaseAmendN' lo) v = (lo + i, WrappedAny v) where i = fromInteger (natVal @n' Proxy)----------------------------------------------------------------------------- | 'select' ('view' 'project') and 'amend' ('set' 'project') in 'Lens'' form.------ @--- 'project' = 'lens' 'select' 'amend'--- @------ @--- let x = (5 :: Int) './' False './' \'X' './' Just \'O' './' 'nil'--- x '^.' ('project' \@'[Int, Maybe Char]) \`shouldBe` (5 :: Int) './' Just \'O' './' 'nil'--- (x '&' ('project' \@'[Int, Maybe Char]) '.~' ((6 :: Int) './' Just 'P' './' 'nil')) \`shouldBe`--- (6 :: Int) './' False './' \'X' './' Just \'P' './' 'nil'--- @-project- :: forall smaller larger.- (Select smaller larger, Amend smaller larger)- => Lens' (Many larger) (Many smaller)-project = lens select amend-{-# INLINE project #-}---- | Polymorphic version of project'-project'- :: forall smaller smaller' larger zipped.- (Select smaller larger, Amend' smaller smaller' larger zipped)- => Lens (Many larger) (Many (Replaces smaller smaller' larger)) (Many smaller) (Many smaller')-project' = lens select (amend' @smaller @smaller' Proxy)-{-# INLINE project' #-}---- | 'selectL' ('view' 'projectL') and 'amendL' ('set' 'projectL') in 'Lens'' form.------ @--- let x = False './' Tagged \@\"Hi" (5 :: Int) './' Tagged \@Foo False './' Tagged \@Bar \'X' './' Tagged \@\"Bye" \'O' './' 'nil'--- x '^.' ('projectL' \@'[Foo, Bar] Proxy) \`shouldBe` Tagged \@Foo False './' Tagged \@Bar \'X' './' nil--- (x '&' ('projectL' \@'[\"Hi", \"Bye"] Proxy) '.~' (Tagged \@\"Hi" (6 :: Int) './' Tagged \@\"Bye" \'P' './' nil)) '`shouldBe`--- False './' Tagged \@\"Hi" (6 :: Int) './' Tagged \@Foo False './' Tagged \@Bar \'X' './' Tagged \@\"Bye" \'P' './' 'nil'--- @-projectL- :: forall ls smaller larger proxy.- ( Select smaller larger- , Amend smaller larger- , smaller ~ KindsAtLabels ls larger- , IsDistinct ls- , UniqueLabels ls larger)- => proxy ls -> Lens' (Many larger) (Many smaller)-projectL p = lens (selectL p) (amendL p)-{-# INLINE projectL #-}---- | Polymorphic version of projectL'------ @--- let x = False './' Tagged \@\"Hi" (5 :: Int) './' Tagged \@Foo False './' Tagged \@Bar \'X' './' Tagged \@\"Bye" \'O' './' 'nil'--- (x '&' ('projectL'' \@'[\"Hi", \"Bye"] Proxy) '.~' (True './' Tagged \@\"Changed" False './' 'nil')) \`shouldBe`--- False './' True './' Tagged \@Foo False './' Tagged \@Bar \'X' './' Tagged \@\"Changed" False './' 'nil'--- @-projectL'- :: forall ls smaller smaller' larger proxy zipped.- ( Select smaller larger- , Amend' smaller smaller' larger zipped- , smaller ~ KindsAtLabels ls larger- , IsDistinct ls- , UniqueLabels ls larger)- => proxy ls -> Lens (Many larger) (Many (Replaces smaller smaller' larger)) (Many smaller) (Many smaller')-projectL' p = lens (selectL p) (amendL' p)-{-# INLINE projectL' #-}---- | 'selectN' ('view' 'projectN') and 'amendN' ('set' 'projectN') in 'Lens'' form.------ @--- 'projectN' = 'lens' 'selectN' 'amendN'--- @------ @--- let x = (5 :: Int) './' False './' \'X' './' Just \'O' './' (6 :: Int) './' Just \'A' './' 'nil'--- x '^.' ('projectN' \@'[5, 4, 0] Proxy) \`shouldBe` Just \'A' './' (6 :: Int) './' (5 ::Int) './' 'nil'--- (x '&' ('projectN' \@'[5, 4, 0] Proxy) '.~' (Just \'B' './' (8 :: Int) './' (4 ::Int) './' nil)) \`shouldBe`--- (4 :: Int) './' False './' \'X' './' Just \'O' './' (8 :: Int) './' Just \'B' './' 'nil'--- @-projectN- :: forall ns smaller larger proxy.- (SelectN ns smaller larger, AmendN ns smaller larger)- => proxy ns -> Lens' (Many larger) (Many smaller)-projectN p = lens (selectN p) (amendN p)-{-# INLINE projectN #-}---- | Polymorphic version of 'projectN'-projectN'- :: forall ns smaller smaller' larger proxy zipped.- (SelectN ns smaller larger, AmendN' ns smaller smaller' larger zipped)- => proxy ns -> Lens (Many larger) (Many (ReplacesIndex ns smaller' larger)) (Many smaller) (Many smaller')-projectN' p = lens (selectN p) (amendN' p)-{-# INLINE projectN' #-} -----------------------------------------------------------------------
src/Data/Diverse/Which.hs view
@@ -17,10 +17,6 @@ , trial0 , trialL , trialN- -- ** Lens- , facet- , facetL- , facetN -- * Multiple types -- ** Injection@@ -36,10 +32,6 @@ , reinterpretL , ReinterpretN , reinterpretN- -- ** Lens- , inject- , injectL- , injectN -- * Catamorphism , Switch(..)
src/Data/Diverse/Which/Internal.hs view
@@ -31,10 +31,6 @@ , trial0 , trialL , trialN- -- ** Lens- , facet- , facetL- , facetN -- * Multiple types -- ** Injection@@ -50,10 +46,6 @@ , reinterpretL , ReinterpretN , reinterpretN- -- ** Lens- , inject- , injectL- , injectN -- * Catamorphism , Switch(..)@@ -65,7 +57,6 @@ ) where import Control.Applicative-import Control.Lens import Control.Monad import Data.Diverse.Case import Data.Diverse.Reduce@@ -272,55 +263,8 @@ then Left (Which (n - 1) v) else Left (Which n v) --- | Utility to convert Either to Maybe-hush :: Either a b -> Maybe b-hush = either (const Nothing) Just- ----------------------------------------------------------------- --- | 'pick' ('review' 'facet') and 'trial' ('preview' 'facet') in 'Prism'' form.------ @--- 'facet' = 'prism'' 'pick' (either (const Nothing) Just . 'trial')--- @------ @--- let y = 'review' ('facet' \@Int) (5 :: Int) :: 'Which' '[Bool, Int, Char, Bool, Char] -- 'pick'--- x = 'preview' ('facet' \@Int) y -- 'trial'--- x \`shouldBe` (Just 5)--- @-facet :: forall x xs. (UniqueMember x xs) => Prism' (Which xs) x-facet = prism' pick (hush . trial)-{-# INLINE facet #-}---- | 'pickL' ('review' 'facetL') and 'trialL' ('preview' 'facetL') in 'Prism'' form.------ @--- let y = 'review' ('facetL' \@Bar Proxy) (Tagged (5 :: Int)) :: Which '[Tagged Foo Bool, Tagged Bar Int, Char, Bool, Char]--- x = 'preview' ('facetL' \@Bar Proxy) y--- x \`shouldBe` (Just (Tagged 5))--- @-facetL :: forall l xs x proxy. (UniqueLabelMember l xs, x ~ KindAtLabel l xs) => proxy l -> Prism' (Which xs) x-facetL p = prism' (pickL p) (hush . trialL p)-{-# INLINE facetL #-}---- | 'pickN' ('review' 'facetN') and 'trialN' ('preview' 'facetN') in 'Prism'' form.------ @--- 'facetN' p = 'prism'' ('pickN' p) (either (const Nothing) Just . 'trialN' p)--- @------ @--- let y = 'review' ('facetN' (Proxy \@4)) (5 :: Int) :: 'Which' '[Bool, Int, Char, Bool, Int, Char] -- 'pickN'--- x = 'preview' ('facetN' (Proxy \@4)) y -- 'trialN'--- x \`shouldBe` (Just 5)--- @-facetN :: forall n xs x proxy. (MemberAt n x xs) => proxy n -> Prism' (Which xs) x-facetN p = prism' (pickN p) (hush . trialN p)-{-# INLINE facetN #-}--------------------------------------------------------------------- -- | A friendlier constraint synonym for 'diversify'. type Diversify (tree :: [Type]) (branch :: [Type]) = Reduce (Which branch) (Switch (CaseDiversify tree branch) branch) (Which tree) @@ -505,67 +449,6 @@ case fromInteger (natVal @n' Proxy) of 0 -> Nothing i -> Just $ Which (i - 1) (unsafeCoerce a)---- ---------------------------------------------------------------------- | 'diversify' ('review' 'inject') and 'reinterpret' ('preview' 'inject') in 'Prism'' form.------ @--- let x = 'pick' (5 :: Int) :: 'Which' '[String, Int]--- y = 'review' ('inject' \@_ \@[Bool, Int, Char, String]) x -- 'diversify'--- y \`shouldBe` pick (5 :: Int) :: 'Which' '[Bool, Int, Char, String]--- let y' = 'preview' ('inject' \@[String, Int]) y -- 'reinterpret'--- y' \`shouldBe` Just (pick (5 :: Int)) :: Maybe ('Which' '[String, Int])--- @-inject- :: forall branch tree.- ( Diversify tree branch- , Reinterpret branch tree- )- => Prism' (Which tree) (Which branch)-inject = prism' diversify (hush . reinterpret)-{-# INLINE inject #-}----- | 'diversifyL' ('review' 'injectL') and 'reinterpretL' ('preview' 'injectL') in 'Prism'' form.------ @--- let t = 'pick' \@[Tagged Bar Int, Tagged Foo Bool, Tagged Hi Char, Tagged Bye Bool] (5 :: Tagged Bar Int)--- b = 'pick' \@'[Tagged Foo Bool, Tagged Bar Int] (5 :: Tagged Bar Int)--- t' = 'review' ('injectL' \@[Foo, Bar] \@_ \@[Tagged Bar Int, Tagged Foo Bool, Tagged Hi Char, Tagged Bye Bool] Proxy) b--- b' = 'preview' ('injectL' \@[Foo, Bar] Proxy) t'--- t \`shouldBe` t'--- b' \`shouldBe` Just b--- @-injectL- :: forall ls branch tree proxy.- ( Diversify tree branch- , Reinterpret branch tree- , branch ~ KindsAtLabels ls tree- , UniqueLabels ls tree- , IsDistinct ls- )- => proxy ls -> Prism' (Which tree) (Which branch)-injectL p = prism' (diversifyL p) (hush . reinterpretL p)-{-# INLINE injectL #-}---- | 'diversifyN' ('review' 'injectN') and 'reinterpretN' ('preview' 'injectN') in 'Prism'' form.------ @--- let x = 'pick' (5 :: Int) :: 'Which' '[String, Int]--- y = 'review' (injectN \@[3, 1] \@_ \@[Bool, Int, Char, String] Proxy) x -- 'diversifyN'--- y \`shouldBe` pick (5 :: Int) :: 'Which' '[Bool, Int, Char, String]--- let y' = 'preview' ('injectN' @[3, 1] \@[String, Int] Proxy) y -- 'reinterpertN''--- y' \`shouldBe` Just ('pick' (5 :: Int)) :: Maybe ('Which' '[String, Int])--- @-injectN- :: forall indices branch tree proxy.- ( DiversifyN indices tree branch- , ReinterpretN indices branch tree- )- => proxy indices -> Prism' (Which tree) (Which branch)-injectN p = prism' (diversifyN p) (reinterpretN p)-{-# INLINE injectN #-} ------------------------------------------------------------------
test/Data/Diverse/ManySpec.hs view
@@ -8,7 +8,6 @@ module Data.Diverse.ManySpec (main, spec) where -import Control.Lens import Data.Diverse import Data.Tagged import Data.Typeable@@ -63,9 +62,7 @@ let x = (5 :: Int) ./ False ./ 'X' ./ Just 'O' ./ nil t = ((5 :: Int), False, 'X', Just 'O') x `shouldBe` toMany' t- x `shouldBe` review _Many' t t `shouldBe` fromMany' x- t `shouldBe` view _Many' x it "can construct using 'single', 'nil', 'prefix', 'postfix', 'append'" $ do let x = (5 :: Int) ./ False ./ 'X' ./ Just 'O' ./ nil@@ -203,56 +200,6 @@ replace @Char y 'Y' `shouldBe` (5 :: Int) ./ False ./ 'Y' ./ Just 'O' ./ (6 :: Int) ./ Just 'A' ./ nil - it "has getter/setter lens using 'item'" $ do- let x = (5 :: Int) ./ False ./ 'X' ./ Just 'O' ./ nil- x ^. item @Int `shouldBe` 5- (x & item @Int .~ 6) `shouldBe` (6 :: Int) ./ False ./ 'X' ./ Just 'O' ./ nil- x ^. item @Bool `shouldBe` False- (x & item @Bool .~ True) `shouldBe` (5 :: Int) ./ True ./ 'X' ./ Just 'O' ./ nil- x ^. item @Char `shouldBe` 'X'- x ^. item @(Maybe Char) `shouldBe` Just 'O'-- it "has polymorphic getter/setter lens using 'item''" $ do- let x = (5 :: Int) ./ False ./ 'X' ./ Just 'O' ./ nil- (x & item' @(Maybe Char) .~ Just 'P') `shouldBe` (5 :: Int) ./ False ./ 'X' ./ Just 'P' ./ nil- (x & item' @Int .~ 'Z') `shouldBe` 'Z' ./ False ./ 'X' ./ Just 'O' ./ nil- (x & item' @Bool .~ 'Z') `shouldBe` (5 :: Int) ./ 'Z' ./ 'X' ./ Just 'O' ./ nil- (x & item' @Char .~ True) `shouldBe` (5 :: Int) ./ False ./ True ./ Just 'O' ./ nil- (x & item' @(Maybe Char) .~ 'P') `shouldBe` (5 :: Int) ./ False ./ 'X' ./ 'P' ./ nil-- it "has getter/setter lens using 'item'" $ do- let x = (5 :: Int) ./ Tagged @Foo False ./ Tagged @Bar 'X' ./ nil- x ^. itemL @Foo Proxy `shouldBe` Tagged @Foo False- (x & itemL @Foo Proxy .~ Tagged @Foo True) `shouldBe` (5 :: Int) ./ Tagged @Foo True ./ Tagged @Bar 'X' ./ nil-- it "has polymorphic getter/setter lens using 'itemL''" $ do- let x = (5 :: Int) ./ Tagged @Foo False ./ Tagged @Bar 'X' ./ nil- (x & itemL' @Foo Proxy .~ "foo") `shouldBe` (5 :: Int) ./ "foo" ./ Tagged @Bar 'X' ./ nil-- it "has getter/setter lens for duplicate fields using 'itemN'" $ do- let x = (5 :: Int) ./ False ./ 'X' ./ Just 'O' ./ (6 :: Int) ./ Just 'A' ./ nil- x ^. itemN (Proxy @0) `shouldBe` 5- (x & itemN (Proxy @0) .~ 6) `shouldBe` (6 :: Int) ./ False ./ 'X' ./ Just 'O' ./ (6 :: Int) ./ Just 'A' ./ nil- x ^. itemN (Proxy @1) `shouldBe` False- (x & itemN (Proxy @1) .~ True) `shouldBe` (5 :: Int) ./ True ./ 'X' ./ Just 'O' ./ (6 :: Int) ./ Just 'A' ./ nil- x ^. itemN (Proxy @2) `shouldBe` 'X'- (x & itemN (Proxy @2) .~ 'O') `shouldBe` (5 :: Int) ./ False ./ 'O' ./ Just 'O' ./ (6 :: Int) ./ Just 'A' ./ nil- x ^. itemN (Proxy @3) `shouldBe` Just 'O'- (x & itemN (Proxy @3) .~ Just 'P') `shouldBe` (5 :: Int) ./ False ./ 'X' ./ Just 'P' ./ (6 :: Int) ./ Just 'A' ./ nil- x ^. itemN (Proxy @4) `shouldBe` 6- (x & itemN (Proxy @4) .~ 7) `shouldBe` (5 :: Int) ./ False ./ 'X' ./ Just 'O' ./ (7 :: Int) ./ Just 'A' ./ nil- x ^. itemN (Proxy @5) `shouldBe` Just 'A'- (x & itemN (Proxy @5) .~ Just 'B') `shouldBe` (5 :: Int) ./ False ./ 'X' ./ Just 'O' ./ (6 :: Int) ./ Just 'B' ./ nil-- it "has polymorphic getter/setter lens for duplicate fields using 'itemN''" $ do- let x = (5 :: Int) ./ False ./ 'X' ./ Just 'O' ./ (6 :: Int) ./ Just 'A' ./ nil- (x & itemN' (Proxy @0) .~ "Foo") `shouldBe` "Foo" ./ False ./ 'X' ./ Just 'O' ./ (6 :: Int) ./ Just 'A' ./ nil- (x & itemN' (Proxy @1) .~ "Foo") `shouldBe` (5 :: Int) ./ "Foo" ./ 'X' ./ Just 'O' ./ (6 :: Int) ./ Just 'A' ./ nil- (x & itemN' (Proxy @2) .~ "Foo") `shouldBe` (5 :: Int) ./ False ./ "Foo" ./ Just 'O' ./ (6 :: Int) ./ Just 'A' ./ nil- (x & itemN' (Proxy @3) .~ "Foo") `shouldBe` (5 :: Int) ./ False ./ 'X' ./ "Foo" ./ (6 :: Int) ./ Just 'A' ./ nil- (x & itemN' (Proxy @4) .~ "Foo") `shouldBe` (5 :: Int) ./ False ./ 'X' ./ Just 'O' ./ "Foo" ./ Just 'A' ./ nil- (x & itemN' (Proxy @5) .~ "Foo") `shouldBe` (5 :: Int) ./ False ./ 'X' ./ Just 'O' ./ (6 :: Int) ./ "Foo" ./ nil- it "has getter for multiple fields using 'select'" $ do let x = (5 :: Int) ./ False ./ 'X' ./ Just 'O' ./ nil select @'[Int, Maybe Char] x `shouldBe` (5 :: Int) ./ Just 'O' ./ nil@@ -328,39 +275,6 @@ let x = (5 :: Int) ./ False ./ 'X' ./ Just 'O' ./ (6 :: Int) ./ Just 'A' ./ nil amend @ '[Bool, Char] x (True ./ 'B' ./ nil) `shouldBe` (5 :: Int) ./ True ./ 'B' ./ Just 'O' ./ (6 :: Int) ./ Just 'A' ./ nil-- it "has getter/setter lens for multiple fields using 'project'" $ do- let x = (5 :: Int) ./ False ./ 'X' ./ Just 'O' ./ nil- x ^. (project @'[Int, Maybe Char]) `shouldBe` (5 :: Int) ./ Just 'O' ./ nil- (x & (project @'[Int, Maybe Char]) .~ ((6 :: Int) ./ Just 'P' ./ nil)) `shouldBe`- (6 :: Int) ./ False ./ 'X' ./ Just 'P' ./ nil-- it "has polymorphic getter/setter lens for multiple fields using 'project'" $ do- let x = (5 :: Int) ./ False ./ 'X' ./ Just 'O' ./ nil- (x & (project' @'[Int, Maybe Char]) .~ ("Foo" ./ Just "Bar" ./ nil)) `shouldBe`- "Foo" ./ False ./ 'X' ./ Just "Bar" ./ nil-- it "has getter/setter lens for multiple labelled fields using 'projectL'" $ do- let x = False ./ Tagged @"Hi" (5 :: Int) ./ Tagged @Foo False ./ Tagged @Bar 'X' ./ Tagged @"Bye" 'O' ./ nil- x ^. (projectL @'[Foo, Bar] Proxy) `shouldBe` Tagged @Foo False ./ Tagged @Bar 'X' ./ nil- (x & (projectL @'["Hi", "Bye"] Proxy) .~ (Tagged @"Hi" (6 :: Int) ./ Tagged @"Bye" 'P' ./ nil)) `shouldBe`- False ./ Tagged @"Hi" (6 :: Int) ./ Tagged @Foo False ./ Tagged @Bar 'X' ./ Tagged @"Bye" 'P' ./ nil-- it "has polymorphic getter/setter lens for multiple labelled fields using 'projectL''" $ do- let x = False ./ Tagged @"Hi" (5 :: Int) ./ Tagged @Foo False ./ Tagged @Bar 'X' ./ Tagged @"Bye" 'O' ./ nil- (x & (projectL' @'["Hi", "Bye"] Proxy) .~ (True ./ Tagged @"Changed" False ./ nil)) `shouldBe`- False ./ True ./ Tagged @Foo False ./ Tagged @Bar 'X' ./ Tagged @"Changed" False ./ nil-- it "has getter/setter lens for multiple fields with duplicates using 'projectN'" $ do- let x = (5 :: Int) ./ False ./ 'X' ./ Just 'O' ./ (6 :: Int) ./ Just 'A' ./ nil- x ^. (projectN @'[5, 4, 0] Proxy) `shouldBe` Just 'A' ./ (6 :: Int) ./ (5 ::Int) ./ nil- (x & (projectN @'[5, 4, 0] Proxy) .~ (Just 'B' ./ (8 :: Int) ./ (4 ::Int) ./ nil)) `shouldBe`- (4 :: Int) ./ False ./ 'X' ./ Just 'O' ./ (8 :: Int) ./ Just 'B' ./ nil-- it "has polymorphic getter/setter lens for multiple fields with duplicates using 'projectN'" $ do- let x = (5 :: Int) ./ False ./ 'X' ./ Just 'O' ./ (6 :: Int) ./ Just 'A' ./ nil- (x & (projectN' @'[5, 4, 0] Proxy) .~ (Just "Foo" ./ (8 :: Int) ./ "Bar" ./ nil)) `shouldBe`- "Bar" ./ False ./ 'X' ./ Just 'O' ./ (8 :: Int) ./ Just "Foo" ./ nil it "can be folded with 'Many' handlers using 'forMany' or 'collect'" $ do let x = (5 :: Int) ./ False ./ 'X' ./ Just 'O' ./ (6 :: Int) ./ Just 'A' ./ nil
test/Data/Diverse/WhichSpec.hs view
@@ -8,7 +8,6 @@ module Data.Diverse.WhichSpec (main, spec) where -import Control.Lens import Data.Diverse import Data.Tagged import Data.Typeable@@ -131,21 +130,6 @@ trial0 f `shouldBe` Right 5 obvious f `shouldBe` 5 - it "can be constructed and destructed by type with 'facet'" $ do- let y = review (facet @Int) (5 :: Int) :: Which '[Bool, Int, Char, Bool, Char]- x = preview (facet @Int) y- x `shouldBe` (Just 5)-- it "can be constructed and destructed by label with 'facetL'" $ do- let y = review (facetL @Bar Proxy) (Tagged (5 :: Int)) :: Which '[Tagged Foo Bool, Tagged Bar Int, Char, Bool, Char]- x = preview (facetL @Bar Proxy) y- x `shouldBe` (Just (Tagged 5))-- it "can be constructed and destructed by index with 'facetN'" $ do- let y = review (facetN (Proxy @4)) (5 :: Int) :: Which '[Bool, Int, Char, Bool, Int, Char]- x = preview (facetN (Proxy @4)) y- x `shouldBe` (Just 5)- it "can be extended and rearranged by type with 'diversify'" $ do let y = pickOnly (5 :: Int) y' = diversify @[Int, Bool] y@@ -217,28 +201,6 @@ a' = reinterpretN @[3, 0] @[Bool, Char] Proxy y a `shouldBe` Just (pick (5 :: Int)) a' `shouldBe` Nothing-- it "can be 'diversify'ed and 'reinterpreted' by type with 'inject'" $ do- let x = pick (5 :: Int) :: Which '[String, Int]- y = review (inject @_ @[Bool, Int, Char, String]) x- y `shouldBe` pick (5 :: Int)- let y' = preview (inject @[String, Int]) y- y' `shouldBe` Just (pick (5 :: Int))-- it "can be 'diversifyL'ed and 'reinterpretedL' by label with 'injectL'" $ do- let t = pick @[Tagged Bar Int, Tagged Foo Bool, Tagged Hi Char, Tagged Bye Bool] (5 :: Tagged Bar Int)- b = pick @'[Tagged Foo Bool, Tagged Bar Int] (5 :: Tagged Bar Int)- t' = review (injectL @[Foo, Bar] @_ @[Tagged Bar Int, Tagged Foo Bool, Tagged Hi Char, Tagged Bye Bool] Proxy) b- b' = preview (injectL @[Foo, Bar] Proxy) t'- t `shouldBe` t'- b' `shouldBe` Just b-- it "can be 'diversifyN'ed and 'reinterpretedN' by index with 'injectN'" $ do- let x = pick (5 :: Int) :: Which '[String, Int]- y = review (injectN @[3, 1] @_ @[Bool, Int, Char, String] Proxy) x- y `shouldBe` pick (5 :: Int)- let y' = preview (injectN @[3, 1] @[String, Int] Proxy) y- y' `shouldBe` Just (pick (5 :: Int)) it "can be 'switch'ed with 'Many' handlers in any order" $ do let y = pickN @0 Proxy (5 :: Int) :: Which '[Int, Bool, Bool, Int]