Skip to content

Commit 8472858

Browse files
committed
Add newtype isos
1 parent 8fbe327 commit 8472858

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/Data/Profunctor.purs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module Data.Profunctor where
22

33
import Prelude
4+
import Data.Newtype (class Newtype, wrap, unwrap)
45

56
-- | A `Profunctor` is a `Functor` from the pair category `(Type^op, Type)`
67
-- | to `Type`.
@@ -33,5 +34,11 @@ rmap b2c = dimap id b2c
3334
arr :: forall a b p. (Category p, Profunctor p) => (a -> b) -> p a b
3435
arr f = rmap f id
3536

37+
unwrapIso :: forall p t a. (Profunctor p, Newtype t a) => p t t -> p a a
38+
unwrapIso = dimap wrap unwrap
39+
40+
wrapIso :: forall p t a. (Profunctor p, Newtype t a) => (t -> a) -> p a a -> p t t
41+
wrapIso _ = dimap unwrap wrap
42+
3643
instance profunctorFn :: Profunctor (->) where
3744
dimap a2b c2d b2c = a2b >>> b2c >>> c2d

0 commit comments

Comments
 (0)