summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorqfpl <>2019-01-11 04:07:00 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2019-01-11 04:07:00 (GMT)
commit2b2ff071105e1fff343c32395c58a32aa040e47a (patch)
tree19ec8178abc679e1aeac4fcddcaabc77af77c440
parentf63b5b0e48c7acef4089b29b12f6c0b745279246 (diff)
version 0.3.0.4HEAD0.3.0.4master
-rw-r--r--changelog.md4
-rw-r--r--natural.cabal2
-rw-r--r--src/Natural.hs21
3 files changed, 26 insertions, 1 deletions
diff --git a/changelog.md b/changelog.md
index 617cc1a..34f0eca 100644
--- a/changelog.md
+++ b/changelog.md
@@ -1,3 +1,7 @@
+0.3.0.4
+
+* add `naturalPositive` iso and `instance AsPositive Natural` prism.
+
0.3.0.3
* added some more functions.
diff --git a/natural.cabal b/natural.cabal
index e877218..d213085 100644
--- a/natural.cabal
+++ b/natural.cabal
@@ -1,7 +1,7 @@
-- documentation, see http://haskell.org/cabal/users-guide/
name: natural
-version: 0.3.0.3
+version: 0.3.0.4
synopsis: Natural number
description:
<<http://i.imgur.com/uZnp9ke.png>>
diff --git a/src/Natural.hs b/src/Natural.hs
index 1337199..5e93e3e 100644
--- a/src/Natural.hs
+++ b/src/Natural.hs
@@ -36,6 +36,7 @@ module Natural (
, SumPositive(..)
, MaxPositive(..)
, MinPositive(..)
+, naturalPositive
, one
, one'
, successor1
@@ -543,6 +544,26 @@ instance Semigroup MinPositive where
MinPositive (Positive x) <> MinPositive (Positive y) =
MinPositive (Positive (x `min` y))
+naturalPositive ::
+ Iso' Natural (Maybe Positive)
+naturalPositive =
+ iso
+ (\(Natural n) ->
+ if n == 0 then Nothing else Just (Positive n))
+ (\x -> Natural (
+ case x of
+ Nothing ->
+ 0
+ Just (Positive n) ->
+ n)
+ )
+
+instance AsPositive Natural where
+ _Positive =
+ prism'
+ (\(Positive n) -> Natural n)
+ (\(Natural n) -> if n == 0 then Nothing else Just (Positive n))
+
one ::
Prism'
Positive