Skip to content

Commit a52b4fc

Browse files
authored
Merge pull request #54 from themoritz/non
add non iso
2 parents a5c44b1 + 5cdf568 commit a52b4fc

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/Data/Lens.purs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module Data.Lens
2222
, module Data.Lens.Common
2323
) where
2424

25-
import Data.Lens.Iso (AnIso, AnIso', Iso, Iso', Optic, Exchange(..), Re(..), au, auf, cloneIso, curried, flipped, iso, re, uncurried, under, withIso)
25+
import Data.Lens.Iso (AnIso, AnIso', Iso, Iso', Optic, Exchange(..), Re(..), au, auf, cloneIso, non, curried, flipped, iso, re, uncurried, under, withIso)
2626
import Data.Lens.Lens (ALens, ALens', Lens, Lens', cloneLens, lens, lens', withLens)
2727
import Data.Lens.Prism (APrism, APrism', Prism, Prism', Review, Review', clonePrism, is, isn't, matching, nearly, only, prism, prism', review, withPrism)
2828
import Data.Lens.Traversal (Traversal, Traversal', element, elementsOf, failover, itraverseOf, sequenceOf, traverseOf, traversed)

src/Data/Lens/Iso.purs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
-- | This module defines functions for working with isomorphisms.
22
module Data.Lens.Iso
3-
( iso, withIso, cloneIso, re, au, auf, under, curried, uncurried, flipped, mapping, dimapping
3+
( iso, withIso, cloneIso, re, au, auf, under, non, curried, uncurried, flipped, mapping, dimapping
44
, module Data.Lens.Types
55
) where
66

77
import Prelude
8-
98
import Data.Lens.Types (Iso, Iso', AnIso, AnIso', Optic, Exchange(..), Re(..))
9+
import Data.Maybe (Maybe(..), fromMaybe)
1010
import Data.Profunctor (class Profunctor, dimap, rmap)
1111
import Data.Tuple (Tuple, curry, uncurry)
1212
import Data.Newtype (unwrap)
@@ -37,6 +37,11 @@ auf l = withIso l \sa bt f g e -> bt (f (rmap sa g) e)
3737
under :: forall s t a b. AnIso s t a b -> (t -> s) -> b -> a
3838
under l = withIso l \sa bt ts -> sa <<< ts <<< bt
3939

40+
non :: forall a. Eq a => a -> Iso' (Maybe a) a
41+
non def = iso (fromMaybe def) g
42+
where g a | a == def = Nothing
43+
| otherwise = Just a
44+
4045
curried :: forall a b c d e f. Iso (Tuple a b -> c) (Tuple d e -> f) (a -> b -> c) (d -> e -> f)
4146
curried = iso curry uncurry
4247

0 commit comments

Comments
 (0)