@@ -23,11 +23,11 @@ module Control.Optics.Linear.Internal
23
23
, _Just , _Nothing
24
24
, traversed
25
25
-- * Using optics
26
- , get , set , gets
26
+ , get , set , gets , setSwap
27
27
, match , build
28
28
, over , over'
29
29
, traverseOf , traverseOf'
30
- , lengthOf
30
+ , toListOf , lengthOf
31
31
, withIso , withPrism
32
32
-- * Constructing optics
33
33
, iso , prism
@@ -38,6 +38,7 @@ import qualified Control.Arrow as NonLinear
38
38
import qualified Data.Bifunctor.Linear as Bifunctor
39
39
import Data.Bifunctor.Linear (SymmetricMonoidal )
40
40
import Data.Profunctor.Linear
41
+ import Data.Functor.Compose hiding (getCompose )
41
42
import Data.Functor.Linear
42
43
import qualified Data.Profunctor.Kleisli.Linear as Linear
43
44
import Data.Void
@@ -97,6 +98,9 @@ over (Optical l) f = getLA (l (LA f))
97
98
traverseOf :: Optic_ (Linear. Kleisli f ) a b s t -> (a #-> f b ) -> s #-> f t
98
99
traverseOf (Optical l) f = Linear. runKleisli (l (Linear. Kleisli f))
99
100
101
+ toListOf :: Optic_ (NonLinear. Kleisli (Const [a ])) a b s t -> s -> [a ]
102
+ toListOf l = gets l (\ a -> [a])
103
+
100
104
get :: Optic_ (NonLinear. Kleisli (Const a )) a b s t -> s -> a
101
105
get l = gets l P. id
102
106
@@ -106,6 +110,12 @@ gets (Optical l) f s = getConst' (NonLinear.runKleisli (l (NonLinear.Kleisli (Co
106
110
set :: Optic_ (-> ) a b s t -> b -> s -> t
107
111
set (Optical l) x = l (const x)
108
112
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
+
109
119
match :: Optic_ (Market a b ) a b s t -> s #-> Either t a
110
120
match (Optical l) = snd (runMarket (l (Market id Right )))
111
121
0 commit comments