smash-lens 0.1.0.0 → 0.1.0.1
raw patch · 5 files changed
+101/−42 lines, 5 filesPVP: minor bump suggested
API additions: PVP suggests at least a minor version bump
API changes (from Hackage documentation)
+ Data.Can.Lens: _CanIso :: Iso (Can a b) (Can c d) (Maybe a, Maybe b) (Maybe c, Maybe d)
+ Data.Smash.Lens: _SmashIso :: Iso (Smash a b) (Smash c d) (Maybe (a, b)) (Maybe (c, d))
+ Data.Wedge.Lens: _WedgeIso :: Iso (Wedge a b) (Wedge c d) (Maybe (Either a b)) (Maybe (Either c d))
Files
- CHANGELOG.md +4/−0
- smash-lens.cabal +35/−33
- src/Data/Can/Lens.hs +20/−2
- src/Data/Smash/Lens.hs +22/−5
- src/Data/Wedge/Lens.hs +20/−2
CHANGELOG.md view
@@ -1,5 +1,9 @@ # Revision history for smash-lens +## 0.1.0.1++* Add `Iso`s for `Wedge`, `Can`, and `Smash`. [#14](https://github.com/emilypi/smash/pull/14)+ ## 0.1.0.0 -- YYYY-mm-dd * First version. Released on an unsuspecting world.
smash-lens.cabal view
@@ -1,52 +1,54 @@-cabal-version: 2.0---name: smash-lens-version: 0.1.0.0-synopsis: Optics for the `smash` library+cabal-version: 2.0+name: smash-lens+version: 0.1.0.1+synopsis: Optics for the `smash` library description: Prisms, Traversals, and combinators for the `smash` library. -homepage: https://github.com/emilypi/smash-bug-reports: https://github.com/emilypi/smash/issues-license: BSD3-license-file: LICENSE-author: Emily Pillmore-maintainer: emilypi@cohomolo.gy-copyright: (c) 2020 Emily Pillmore <emilypi@cohomolo.gy>-category: Data-build-type: Simple+homepage: https://github.com/emilypi/smash+bug-reports: https://github.com/emilypi/smash/issues+license: BSD3+license-file: LICENSE+author: Emily Pillmore+maintainer: emilypi@cohomolo.gy+copyright: (c) 2020 Emily Pillmore <emilypi@cohomolo.gy>+category: Data+build-type: Simple extra-source-files: CHANGELOG.md README.md - tested-with:- GHC ==8.2.2 || ==8.4.3 || ==8.4.4 || ==8.6.3 || ==8.6.5 || ==8.8.3 || ==8.10.1-+ GHC ==8.2.2+ || ==8.4.4+ || ==8.6.5+ || ==8.8.4+ || ==8.10.2 source-repository head type: git location: https://github.com/emilypi/smash.git library- exposed-modules: Data.Can.Lens- , Data.Smash.Lens- , Data.Wedge.Lens+ exposed-modules:+ Data.Can.Lens+ Data.Smash.Lens+ Data.Wedge.Lens+ -- other-modules: -- other-extensions:- build-depends: base >=4.10 && <5.0- , lens >=4.0 && <5.0- , smash ^>= 0.1-- hs-source-dirs: src- default-language: Haskell2010+ build-depends:+ base >=4.10 && <5.0+ , lens >=4.0 && <5.0+ , smash ^>=0.1 - ghc-options: -Wall+ hs-source-dirs: src+ default-language: Haskell2010+ ghc-options: -Wall test-suite smash-lens-test- default-language: Haskell2010- type: exitcode-stdio-1.0- hs-source-dirs: test- main-is: MyLibTest.hs- build-depends: base >=4.10 && <5.0+ default-language: Haskell2010+ type: exitcode-stdio-1.0+ hs-source-dirs: test+ main-is: MyLibTest.hs+ build-depends: base >=4.10 && <5.0
src/Data/Can/Lens.hs view
@@ -16,8 +16,10 @@ -- 'Prism's and 'Traversal's for the 'Can' datatype. -- module Data.Can.Lens-( -- * Prisms- _Non+( -- * Isos+ _CanIso+ -- * Prisms+, _Non , _One , _Eno , _Two@@ -32,6 +34,22 @@ import Control.Lens import Data.Can+++-- ------------------------------------------------------------------- --+-- Isos++-- | A 'Control.Lens.Iso' between a wedge coproduct and pointed coproduct.+--+_CanIso :: Iso (Can a b) (Can c d) (Maybe a, Maybe b) (Maybe c, Maybe d)+_CanIso = iso f g+ where+ f t = (canFst t, canSnd t)++ g (Nothing, Nothing) = Non+ g (Just a, Nothing) = One a+ g (Nothing, Just b) = Eno b+ g (Just a, Just b) = Two a b -- ------------------------------------------------------------------- -- -- Traversals
src/Data/Smash/Lens.hs view
@@ -16,8 +16,10 @@ -- 'Prism's and 'Traversal's for the 'Smash' datatype. -- module Data.Smash.Lens-( -- * Prisms- _Nada+( -- * Isos+ _SmashIso+ -- * Prisms+, _Nada , _Smash -- * Traversals , smashed@@ -29,16 +31,31 @@ import Data.Smash + -- ------------------------------------------------------------------- --+-- Isos++-- | A 'Control.Lens.Iso' between a smash product and pointed tuple.+--+_SmashIso :: Iso (Smash a b) (Smash c d) (Maybe (a,b)) (Maybe (c,d))+_SmashIso = iso f g+ where+ f Nada = Nothing+ f (Smash a b) = Just (a,b)++ g Nothing = Nada+ g (Just (a,b)) = Smash a b++-- ------------------------------------------------------------------- -- -- Traversals -- | A 'Control.Lens.Traversal' of the smashed pair, suitable for use -- with "Control.Lens". ----- >>> over smashed show (Smash 1 2)--- "(1,2)"+-- >>> over smashed (fmap pred) (Smash 1 2)+-- Smash 1 1 ----- >>> over smashed show Nada+-- >>> over smashed id Nada -- Nada -- smashed :: Traversal (Smash a b) (Smash c d) (a,b) (c,d)
src/Data/Wedge/Lens.hs view
@@ -16,8 +16,10 @@ -- 'Prism's and 'Traversal's for the 'Wedge' datatype. -- module Data.Wedge.Lens-( -- * Traversals- here+( -- * Isos+ _WedgeIso+ -- * Traversals+, here , there -- * Prisms , _Nowhere@@ -29,6 +31,22 @@ import Control.Lens import Data.Wedge++-- ------------------------------------------------------------------- --+-- Isos++-- | A 'Control.Lens.Iso' between a wedge sum and pointed coproduct.+--+_WedgeIso :: Iso (Wedge a b) (Wedge c d) (Maybe (Either a b)) (Maybe (Either c d))+_WedgeIso = iso f g+ where+ f Nowhere = Nothing+ f (Here a) = Just (Left a)+ f (There b) = Just (Right b)++ g Nothing = Nowhere+ g (Just (Left a)) = Here a+ g (Just (Right b)) = There b -- ------------------------------------------------------------------- -- -- Traversals