File tree Expand file tree Collapse file tree 2 files changed +33
-2
lines changed Expand file tree Collapse file tree 2 files changed +33
-2
lines changed Original file line number Diff line number Diff line change 1+ -- | This module defines the `Tagged` profunctor
2+
3+ module Data.Lens.Internal.Tagged where
4+
5+ import Data.Profunctor
6+ import Data.Profunctor.Choice
7+ import Data.Either
8+
9+ newtype Tagged a b = Tagged b
10+
11+ instance taggedProfunctor :: Profunctor Tagged where
12+ dimap _ g (Tagged x) = Tagged (g x)
13+
14+ instance taggedChoice :: Choice Tagged where
15+ left (Tagged x) = Tagged (Left x)
16+ right (Tagged x) = Tagged (Right x)
17+
18+ unTagged :: forall a b . Tagged a b -> b
19+ unTagged (Tagged x) = x
Original file line number Diff line number Diff line change 11-- | This module defines functions for working with lenses.
22
33module Data.Lens.Prism where
4-
4+
55import Prelude
6-
6+
77import Data.Either
8+ import Data.Profunctor.Star
9+ import Data.Const
10+ import Data.Maybe
11+ import Data.Maybe.First
812import Data.Lens.Types
13+ import Data.Lens.Internal.Tagged
914import Data.Profunctor (dimap , rmap )
1015import Data.Profunctor.Choice (left )
1116
1217-- | Create a `Prism` from a constructor/pattern pair.
1318prism :: forall s t a b . (b -> t ) -> (s -> Either a t ) -> Prism s t a b
1419prism to fro pab = dimap fro (either id id) (left (rmap to pab))
1520
21+ -- | Review a value through a `Prism`.
22+ review :: forall s t a b . Prism s t a b -> b -> t
23+ review p = unTagged <<< p <<< Tagged
24+
25+ -- | Previews the value of a `Prism`, if there is any.
26+ preview :: forall s t a b . Prism s t a b -> s -> Maybe a
27+ preview p = runFirst <<< getConst <<< runStar (p (Star (Const <<< pure)))
You can’t perform that action at this time.
0 commit comments