Skip to content

Commit 1045d98

Browse files
authored
Merge pull request #86 from edmundnoble/push-vltxotnpoxqt
Use setters instead of lenses in ..: and %.:
2 parents 6ae82bd + 9f27c99 commit 1045d98

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

src/Configuration/Utils/ConfigFile.hs

+4-4
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ fromText = id
126126
-- > e → fail $ "unrecognized user " ⊕ e
127127
--
128128
setProperty
129-
Lens' a b -- ^ a lens into the target that is updated by the parser
129+
Setter' a b -- ^ a lens into the target that is updated by the parser
130130
T.Text -- ^ the JSON property name
131131
(Value Parser b) -- ^ the JSON 'Value' parser that is used to parse the value of the property
132132
Object -- ^ the parsed JSON 'Value' 'Object'
@@ -158,7 +158,7 @@ setProperty s k p o = case H.lookup (fromText k) o of
158158
-- > <$< user ..: "user" % o
159159
-- > <*< pwd ..: "pwd" % o
160160
--
161-
(..:) FromJSON b Lens' a b T.Text Object Parser (a a)
161+
(..:) FromJSON b Setter' a b T.Text Object Parser (a a)
162162
(..:) s k = setProperty s k parseJSON
163163
infix 6 ..:
164164
{-# INLINE (..:) #-}
@@ -194,7 +194,7 @@ infix 6 ..:
194194
-- > <*< setProperty domain "domain" parseJSON o
195195
--
196196
updateProperty
197-
Lens' a b
197+
Setter' a b
198198
T.Text
199199
(Value Parser (b b))
200200
Object
@@ -230,7 +230,7 @@ updateProperty s k p o = case H.lookup (fromText k) o of
230230
-- > <$< auth %.: "auth" % o
231231
-- > <*< domain ..: "domain" % o
232232
--
233-
(%.:) FromJSON (b b) Lens' a b T.Text Object Parser (a a)
233+
(%.:) FromJSON (b b) Setter' a b T.Text Object Parser (a a)
234234
(%.:) s k = updateProperty s k parseJSON
235235
infix 6 %.:
236236
{-# INLINE (%.:) #-}

src/Configuration/Utils/Internal.hs

+18-3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ module Configuration.Utils.Internal
2121
, view
2222
, Lens'
2323
, Lens
24+
, Setter'
25+
, Setter
2426
, Iso'
2527
, Iso
2628
, iso
@@ -70,15 +72,29 @@ type Lens s t a b = ∀ f . Functor f ⇒ (a → f b) → s → f t
7072
--
7173
type Lens' s a = Lens s s a a
7274

75+
-- | This is almost the same type as the type from the lens library with the same name.
76+
--
77+
-- In case it is already import from the lens package this should be hidden
78+
-- from the import.
79+
--
80+
type Setter s t a b = (a -> Identity b) -> s -> Identity t
81+
82+
-- | This is almost the same type as the type from the lens library with the same name.
83+
--
84+
-- In case it is already import from the lens package this should be hidden
85+
-- from the import.
86+
--
87+
type Setter' s a = Setter s s a a
88+
7389
lens (s a) (s b t) Lens s t a b
7490
lens getter setter lGetter s = setter s `fmap` lGetter (getter s)
7591
{-# INLINE lens #-}
7692

77-
over ((a Identity b) s Identity t) (a b) s t
93+
over Setter s t a b (a b) s t
7894
over s f = runIdentity . s (Identity . f)
7995
{-# INLINE over #-}
8096

81-
set ((a Identity b) s Identity t) b s t
97+
set Setter s t a b b s t
8298
set s a = runIdentity . s (const $ Identity a)
8399
{-# INLINE set #-}
84100

@@ -123,4 +139,3 @@ errorT
123139
m a
124140
errorT = exceptT (\e error T.unpack $ "Error: " e) return
125141
{-# INLINE errorT #-}
126-

0 commit comments

Comments
 (0)