@@ -23,11 +23,11 @@ module Control.Optics.Linear.Internal
2323 , _Just , _Nothing
2424 , traversed
2525 -- * Using optics
26- , get , set , gets
26+ , get , set , gets , setSwap
2727 , match , build
2828 , over , over'
2929 , traverseOf , traverseOf'
30- , lengthOf
30+ , toListOf , lengthOf
3131 , withIso , withPrism
3232 -- * Constructing optics
3333 , iso , prism
@@ -38,6 +38,7 @@ import qualified Control.Arrow as NonLinear
3838import qualified Data.Bifunctor.Linear as Bifunctor
3939import Data.Bifunctor.Linear (SymmetricMonoidal )
4040import Data.Profunctor.Linear
41+ import Data.Functor.Compose hiding (getCompose )
4142import Data.Functor.Linear
4243import qualified Data.Profunctor.Kleisli.Linear as Linear
4344import Data.Void
@@ -97,6 +98,9 @@ over (Optical l) f = getLA (l (LA f))
9798traverseOf :: Optic_ (Linear. Kleisli f ) a b s t -> (a #-> f b ) -> s #-> f t
9899traverseOf (Optical l) f = Linear. runKleisli (l (Linear. Kleisli f))
99100
101+ toListOf :: Optic_ (NonLinear. Kleisli (Const [a ])) a b s t -> s -> [a ]
102+ toListOf l = gets l (\ a -> [a])
103+
100104get :: Optic_ (NonLinear. Kleisli (Const a )) a b s t -> s -> a
101105get l = gets l P. id
102106
@@ -106,6 +110,12 @@ gets (Optical l) f s = getConst' (NonLinear.runKleisli (l (NonLinear.Kleisli (Co
106110set :: Optic_ (-> ) a b s t -> b -> s -> t
107111set (Optical l) x = l (const x)
108112
113+ setSwap :: Optic_ (Linear. Kleisli (Compose (LinearArrow b ) ((,) a ))) a b s t -> s #-> b #-> (a , t )
114+ setSwap (Optical l) s = getLA (getCompose (Linear. runKleisli (l (Linear. Kleisli (\ a -> Compose (LA (\ b -> (a,b)))))) s))
115+ where
116+ getCompose :: Compose f g a #-> f (g a )
117+ getCompose (Compose x) = x
118+
109119match :: Optic_ (Market a b ) a b s t -> s #-> Either t a
110120match (Optical l) = snd (runMarket (l (Market id Right )))
111121
0 commit comments