git.iko.soy/semi-iso-optics
on master help sign in
Bump version to 0.4.2.0. Add 'cloneSemiIso' and '/?/'.
84b6967Paweł Nowak
Control/Lens/SemiIso.hs+5
@@ -48,6 +48,7 @@ module Control.Lens.SemiIso (
48
48
49 -- * Constructing semi-isos.
49 -- * Constructing semi-isos.
50 semiIso,
50 semiIso,
51+ cloneSemiIso,
51
52
52 -- * Consuming semi-isos.
53 -- * Consuming semi-isos.
53 apply,
54 apply,
@@ -131,6 +132,10 @@ pattern SemiIso sa bt <- (viewSemiIso -> (sa, bt))
131semiIso :: (s -> Either String a) -> (b -> Either String t) -> SemiIso s t a b
132semiIso :: (s -> Either String a) -> (b -> Either String t) -> SemiIso s t a b
132semiIso sa bt = merge . dimap sa (sequenceA . fmap bt) . expose
133semiIso sa bt = merge . dimap sa (sequenceA . fmap bt) . expose
133
134
135+-- | Clones a semi-iso.
136+cloneSemiIso :: ASemiIso s t a b -> SemiIso s t a b
137+cloneSemiIso (SemiIso sa bt) = semiIso sa bt
138+
134-- | Applies the 'SemiIso'.
139-- | Applies the 'SemiIso'.
135apply :: ASemiIso s t a b -> s -> Either String a
140apply :: ASemiIso s t a b -> s -> Either String a
136apply (SemiIso sa _) = sa
141apply (SemiIso sa _) = sa
Data/SemiIsoFunctor.hs+8−10
@@ -23,7 +23,7 @@ import Control.Lens.Empty
23import Control.Lens.SemiIso
23import Control.Lens.SemiIso
24import Data.Tuple.Morph
24import Data.Tuple.Morph
25
25
26−infixl 3 /|/
26+infixl 3 /|/, /?/
27infixl 4 /$/, ~$/, /$~, ~$~
27infixl 4 /$/, ~$/, /$~, ~$~
28infixl 5 /*/, /*, */
28infixl 5 /*/, /*, */
29infixl 1 //=
29infixl 1 //=
@@ -66,17 +66,13 @@ class SemiIsoFunctor f where
66(/$~) :: (SemiIsoFunctor f, HFoldable b', HFoldable b,
66(/$~) :: (SemiIsoFunctor f, HFoldable b', HFoldable b,
67 HUnfoldable b', HUnfoldable b, Rep b' ~ Rep b)
67 HUnfoldable b', HUnfoldable b, Rep b' ~ Rep b)
68 => ASemiIso' a b' -> f b -> f a
68 => ASemiIso' a b' -> f b -> f a
69−-- TODO GHC 7.10: haddock doesn't work with pattern synynonyms yet
70−-- (SemiIso f g) /$~ h = semiIso f g . morphed /$/ h
71−ai /$~ h = withSemiIso ai $ \f g -> semiIso f g . morphed /$/ h
69+ai /$~ h = cloneSemiIso ai . morphed /$/ h
72
70
73-- | > ai ~$/ f = morphed . ai /$/ f
71-- | > ai ~$/ f = morphed . ai /$/ f
74(~$/) :: (SemiIsoFunctor f, HFoldable a', HFoldable a,
72(~$/) :: (SemiIsoFunctor f, HFoldable a', HFoldable a,
75 HUnfoldable a', HUnfoldable a, Rep a' ~ Rep a)
73 HUnfoldable a', HUnfoldable a, Rep a' ~ Rep a)
76 => ASemiIso' a' b -> f b -> f a
74 => ASemiIso' a' b -> f b -> f a
77−-- TODO GHC 7.10: haddock doesn't work with pattern synynonyms yet
75+ai ~$/ h = morphed . cloneSemiIso ai /$/ h
78−--(SemiIso f g) ~$/ h = morphed . semiIso f g /$/ h
79−ai ~$/ h = withSemiIso ai $ \f g -> morphed . semiIso f g /$/ h
80
76
81-- | > ai ~$~ f = morphed . ai . morphed /$/ f
77-- | > ai ~$~ f = morphed . ai . morphed /$/ f
82(~$~) :: (SemiIsoFunctor f,
78(~$~) :: (SemiIsoFunctor f,
@@ -85,9 +81,7 @@ ai ~$/ h = withSemiIso ai $ \f g -> morphed . semiIso f g /$/ h
85 HFoldable b', HUnfoldable b',
81 HFoldable b', HUnfoldable b',
86 Rep b' ~ Rep b, Rep b' ~ Rep a)
82 Rep b' ~ Rep b, Rep b' ~ Rep a)
87 => ASemiIso b' b' b' b' -> f b -> f a
83 => ASemiIso b' b' b' b' -> f b -> f a
88−-- TODO GHC 7.10: haddock doesn't work with pattern synynonyms yet
89−--(SemiIso f g) ~$~ h = morphed . semiIso f g . morphed /$/ h
90−ai ~$~ h = withSemiIso ai $ \f g -> morphed . semiIso f g . morphed /$/ h
84+ai ~$~ h = morphed . cloneSemiIso ai . morphed /$/ h
91
85
92-- | Equivalent of 'Applicative' for 'SemiIsoFunctor'.
86-- | Equivalent of 'Applicative' for 'SemiIsoFunctor'.
93--
87--
@@ -137,6 +131,10 @@ class SemiIsoApply f => SemiIsoAlternative f where
137
131
138 {-# MINIMAL siempty, (/|/) #-}
132 {-# MINIMAL siempty, (/|/) #-}
139
133
134+-- | Provides an error message in the case of failure.
135+(/?/) :: SemiIsoAlternative f => f a -> String -> f a
136+f /?/ msg = f /|/ sifail msg
137+
140-- | An analogue of 'Monad' for 'SemiIsoFunctor'.
138-- | An analogue of 'Monad' for 'SemiIsoFunctor'.
141--
139--
142-- Because of the 'no throwing away' rule bind has to \"return\"
140-- Because of the 'no throwing away' rule bind has to \"return\"
semi-iso.cabal+1−1
@@ -1,5 +1,5 @@
1name: semi-iso
1name: semi-iso
2−version: 0.4.1.0
2+version: 0.4.2.0
3synopsis: Weakened partial isomorphisms that work with lenses.
3synopsis: Weakened partial isomorphisms that work with lenses.
4description: Semi-isomorphisms are partial isomorphisms with weakened iso laws.
4description: Semi-isomorphisms are partial isomorphisms with weakened iso laws.
5 And they work with Iso and Prism from @lens@!
5 And they work with Iso and Prism from @lens@!