File tree 4 files changed +13
-21
lines changed
4 files changed +13
-21
lines changed Original file line number Diff line number Diff line change @@ -28,16 +28,6 @@ import Data.Tuple.Solo (Solo (..), getSolo)
28
28
-- Credit for this goes to Eric Mertens, see
29
29
-- <https://github.com/glguy/irc-core/commit/2d5fc45b05f1>.
30
30
31
- instance Mapping (Star Solo ) where
32
- roam f (Star k) = Star $ wrapSolo' . f (getSolo . k)
33
- iroam f (Star k) = Star $ wrapSolo' . f (\ _ -> getSolo . k)
34
-
35
- instance Mapping (IxStar Solo ) where
36
- roam f (IxStar k) =
37
- IxStar $ \ i -> wrapSolo' . f (getSolo . k i)
38
- iroam f (IxStar k) =
39
- IxStar $ \ ij -> wrapSolo' . f (\ i -> getSolo . k (ij i))
40
-
41
31
-- | Mark a value for evaluation to whnf.
42
32
--
43
33
-- This allows us to, when applying a setter to a structure, evaluate only the
Original file line number Diff line number Diff line change @@ -81,11 +81,11 @@ iover o = \f -> runIxFunArrow (getOptic (castOptic @A_Setter o) (IxFunArrow f))
81
81
82
82
-- | Apply an indexed setter as a modifier, strictly.
83
83
iover'
84
- :: (Is k A_Setter , is `HasSingleIndex ` i )
84
+ :: (Is k A_Traversal , is `HasSingleIndex ` i )
85
85
=> Optic k is s t a b
86
86
-> (i -> a -> b ) -> s -> t
87
87
iover' o = \ f ->
88
- let star = getOptic (castOptic @ A_Setter o) $ IxStar (\ i -> wrapSolo' . f i)
88
+ let star = getOptic (castOptic @ A_Traversal o) $ IxStar (\ i -> wrapSolo' . f i)
89
89
in getSolo . runIxStar star id
90
90
91
91
{-# INLINE iover' #-}
@@ -105,7 +105,7 @@ iset o = \f -> iover o (\i _ -> f i)
105
105
106
106
-- | Apply an indexed setter, strictly.
107
107
iset'
108
- :: (Is k A_Setter , is `HasSingleIndex ` i )
108
+ :: (Is k A_Traversal , is `HasSingleIndex ` i )
109
109
=> Optic k is s t a b
110
110
-> (i -> b ) -> s -> t
111
111
iset' o = \ f -> iover' o (\ i _ -> f i)
Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ import Optics.Getter
28
28
import Optics.Optic
29
29
import Optics.Review
30
30
import Optics.Setter
31
+ import Optics.Traversal
31
32
32
33
-- | Flipped infix version of 'view'.
33
34
(^.) :: Is k A_Getter => s -> Optic' k is s a -> a
@@ -65,7 +66,7 @@ infixr 8 #
65
66
infixr 4 %~
66
67
67
68
-- | Infix version of 'over''.
68
- (%!~) :: Is k A_Setter => Optic k is s t a b -> (a -> b ) -> s -> t
69
+ (%!~) :: Is k A_Traversal => Optic k is s t a b -> (a -> b ) -> s -> t
69
70
(%!~) = over'
70
71
{-# INLINE (%!~) #-}
71
72
@@ -79,7 +80,7 @@ infixr 4 %!~
79
80
infixr 4 .~
80
81
81
82
-- | Infix version of 'set''.
82
- (!~) :: Is k A_Setter => Optic k is s t a b -> b -> s -> t
83
+ (!~) :: Is k A_Traversal => Optic k is s t a b -> b -> s -> t
83
84
(!~) = set'
84
85
{-# INLINE (!~) #-}
85
86
@@ -103,7 +104,7 @@ infixr 4 !~
103
104
infixr 4 ?~
104
105
105
106
-- | Strict version of ('?~').
106
- (?!~) :: Is k A_Setter => Optic k is s t a (Maybe b ) -> b -> s -> t
107
+ (?!~) :: Is k A_Traversal => Optic k is s t a (Maybe b ) -> b -> s -> t
107
108
(?!~) = \ o ! b -> set' o (Just b)
108
109
{-# INLINE (?!~) #-}
109
110
Original file line number Diff line number Diff line change @@ -102,11 +102,11 @@ over o = \f -> runFunArrow $ getOptic (castOptic @A_Setter o) (FunArrow f)
102
102
-- 'over' is used, because the first coordinate of a pair is never forced.
103
103
--
104
104
over'
105
- :: Is k A_Setter
105
+ :: Is k A_Traversal
106
106
=> Optic k is s t a b
107
107
-> (a -> b ) -> s -> t
108
108
over' o = \ f ->
109
- let star = getOptic (castOptic @ A_Setter o) $ Star (wrapSolo' . f)
109
+ let star = getOptic (castOptic @ A_Traversal o) $ Star (wrapSolo' . f)
110
110
in getSolo . runStar star
111
111
{-# INLINE over' #-}
112
112
@@ -128,10 +128,11 @@ set o = over o . const
128
128
129
129
-- | Apply a setter, strictly.
130
130
--
131
- -- TODO DOC: what exactly is the strictness property?
132
- --
131
+ -- The new value will be forced if and only if the optic traverses at
132
+ -- least one target. If forcing the new value is inexpensive, then it
133
+ -- is cheaper to do so manually and use 'set'.
133
134
set'
134
- :: Is k A_Setter
135
+ :: Is k A_Traversal
135
136
=> Optic k is s t a b
136
137
-> b -> s -> t
137
138
set' o = over' o . const
You can’t perform that action at this time.
0 commit comments