@@ -32,7 +32,7 @@ module Control.Optics.Linear.Internal
3232 , over , over'
3333 , traverseOf , traverseOf'
3434 , lengthOf
35- , withIso
35+ , withIso , withLens
3636 , toListOf
3737 -- * Constructing optics
3838 , iso , prism , lens
@@ -83,9 +83,11 @@ assoc = iso Bifunctor.lassoc Bifunctor.rassoc
8383(.>) :: Optic_ arr a b s t -> Optic_ arr x y a b -> Optic_ arr x y s t
8484Optical f .> Optical g = Optical (f P. . g)
8585
86- -- c is the complement (probably)
87- lens :: (s ->. (c ,a )) -> ((c ,b ) ->. t ) -> Lens a b s t
88- lens sca cbt = Optical $ \ f -> dimap sca cbt (second f)
86+ lens :: (s ->. (a , b ->. t )) -> Lens a b s t
87+ lens k = Optical $ \ f -> dimap k (\ (x,g) -> g $ x) (first f)
88+
89+ withLens :: Optic_ (Linear. Kleisli (OtherFunctor a b )) a b s t -> s ->. (a , b ->. t )
90+ withLens (Optical l) s = runOtherFunctor (Linear. runKleisli (l (Linear. Kleisli (\ a -> OtherFunctor (a, id )))) s)
8991
9092prism :: (b ->. t ) -> (s ->. Either t a ) -> Prism a b s t
9193prism b s = Optical $ \ f -> dimap s (either id id ) (second (rmap b f))
@@ -167,7 +169,10 @@ gets' :: Optic_ (Linear.Kleisli (Const (Top, r))) a b s t -> (a ->. r) -> s ->.
167169gets' (Optical l) f s = getConst' (Linear. runKleisli (l (Linear. Kleisli (\ a -> Const (mempty , f a)))) s)
168170
169171set' :: Optic_ (Linear. Kleisli (MyFunctor a b )) a b s t -> s ->. b ->. (a , t )
170- set' (Optical l) = runMyFunctor . Linear. runKleisli (l (Linear. Kleisli (\ a -> MyFunctor (\ b -> (a,b)))))
172+ set' (Optical l) s = runMyFunctor (Linear. runKleisli (l (Linear. Kleisli (\ a -> MyFunctor (\ b -> (a,b))))) s)
173+
174+ set'' :: Optic_ (NonLinear. Kleisli (Reader b )) a b s t -> b ->. s -> t
175+ set'' (Optical l) b s = runReader (NonLinear. runKleisli (l (NonLinear. Kleisli (const (Reader id )))) s) b
171176
172177set :: Optic_ (-> ) a b s t -> b -> s -> t
173178set (Optical l) x = l (const x)
0 commit comments