nat-optics 1.0.0.3 → 1.0.0.4
raw patch · 3 files changed
+26/−3 lines, 3 filesPVP: minor bump suggested
API additions: PVP suggests at least a minor version bump
API changes (from Hackage documentation)
+ NatOptics.Signed: intNatIso :: Iso' Integer (Signed Natural)
Files
- nat-optics.cabal +1/−1
- src/NatOptics/Signed.hs +16/−2
- test/Main.hs +9/−0
nat-optics.cabal view
@@ -1,7 +1,7 @@ cabal-version: 3.0 name: nat-optics-version: 1.0.0.3+version: 1.0.0.4 category: Numeric, Optics synopsis:
src/NatOptics/Signed.hs view
@@ -4,14 +4,16 @@ ( Signed (..), intIso,+ intNatIso, ) where import Data.Eq ( Eq ) import Data.Ord ( Ord, compare, Ordering (..) )-import Text.Show ( Show )+import Numeric.Natural ( Natural ) import Optics.Core ( Iso', iso )-import Prelude ( Integer, abs, negate )+import Prelude ( Integer, abs, negate, fromIntegral )+import Text.Show ( Show ) import NatOptics.Positive.Unsafe ( Positive (..) ) @@ -29,3 +31,15 @@ Zero -> 0 Plus (PositiveUnsafe x) -> x Minus (PositiveUnsafe x) -> negate x++intNatIso :: Iso' Integer (Signed Natural)+intNatIso = iso f g+ where+ f x = case compare x 0 of+ EQ -> Zero+ LT -> Minus (PositiveUnsafe (fromIntegral (abs x)))+ GT -> Plus (PositiveUnsafe (fromIntegral x))+ g y = case y of+ Zero -> 0+ Plus (PositiveUnsafe x) -> fromIntegral x+ Minus (PositiveUnsafe x) -> negate (fromIntegral x)
test/Main.hs view
@@ -60,6 +60,15 @@ specify "0" $ review S.intIso S.Zero `shouldBe` 0 specify "3" $ review S.intIso (S.Plus (Pos.PositiveUnsafe 3)) `shouldBe` 3 specify "-5" $ review S.intIso (S.Minus (Pos.PositiveUnsafe 5)) `shouldBe` (-5)+ describe "intNatIso" $ do+ describe "view" $ do+ specify "0" $ view S.intNatIso 0 `shouldBe` S.Zero+ specify "3" $ view S.intNatIso 3 `shouldBe` S.Plus (Pos.PositiveUnsafe 3)+ specify "-5" $ view S.intNatIso (-5) `shouldBe` S.Minus (Pos.PositiveUnsafe 5)+ describe "review" $ do+ specify "0" $ review S.intNatIso S.Zero `shouldBe` 0+ specify "3" $ review S.intNatIso (S.Plus (Pos.PositiveUnsafe 3)) `shouldBe` 3+ specify "-5" $ review S.intNatIso (S.Minus (Pos.PositiveUnsafe 5)) `shouldBe` (-5) mathSpec :: SpecWith () mathSpec = describe "Positive math" $ do