Skip to content

Commit b7357ba

Browse files
committed
A bit of twiddlesome clarification
1 parent 6565862 commit b7357ba

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

examples/src/PrismsForSumTypes.purs

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ Examples are written in this format:
1414
s1 :: Maybe Color
1515
s1 = preview solidFocus (Solid Color.white) -- (Just rgba 255 255 255 1.0)
1616
17-
That's so that a typical syntax highlighter will make the executable code
18-
easy to spot among the commentary. (The name-value binding is unfortunate,
19-
but needed to prevent noise from compiler warnings.)
17+
That's so that a typical syntax highlighter will make the executable
18+
code easy to spot among the commentary. (The name-value bindings and
19+
type annotations are unfortunate clutter, but needed to prevent noise
20+
from compiler warnings.)
2021
2122
-}
2223

@@ -47,9 +48,6 @@ data Fill
4748

4849
{------ Some samples to work with ------}
4950

50-
fillWhite :: Fill
51-
fillWhite = Solid Color.white
52-
5351
fillBlackToWhite :: Fill
5452
fillBlackToWhite = LinearGradient Color.black Color.white $ Percent 3.3
5553

@@ -122,10 +120,10 @@ s3 = review solidFocus Color.white
122120
-- ... or you can ask whether a given value matches the prism:
123121

124122
s4 :: Boolean
125-
s4 = is solidFocus fillWhite :: Boolean -- true
123+
s4 = is solidFocus (Solid Color.white) :: Boolean -- true
126124

127125
s5 :: Boolean
128-
s5 = isn't solidFocus fillWhite :: Boolean -- false
126+
s5 = isn't solidFocus (Solid Color.white) :: Boolean -- false
129127

130128

131129

@@ -172,17 +170,17 @@ l2 = review linearFocus { color1 : Color.black
172170

173171
-- `only` is used to check for a specific value:
174172

175-
whiteSolid :: Prism' Fill Unit
176-
whiteSolid = only (Solid Color.white)
173+
whiteToBlackFocus :: Prism' Fill Unit
174+
whiteToBlackFocus = only fillWhiteToBlack
177175

178176
o1 :: Boolean
179-
o1 = is whiteSolid (Solid Color.white) :: Boolean -- true
177+
o1 = is whiteToBlackFocus fillWhiteToBlack :: Boolean -- true
180178

181179
o2 :: Boolean
182-
o2 = is whiteSolid (Solid Color.black) :: Boolean -- false
180+
o2 = is whiteToBlackFocus fillBlackToWhite :: Boolean -- false
183181

184182
o3 :: Boolean
185-
o3 = is whiteSolid fillRadial :: Boolean -- false
183+
o3 = is whiteToBlackFocus fillRadial :: Boolean -- false
186184

187185

188186
-- `nearly` is typically used to look for a specific case (like other
@@ -194,8 +192,8 @@ o3 = is whiteSolid fillRadial :: Boolean -- false
194192
-- In this example, we want to focus on solid colors that are "bright
195193
-- enough".
196194

197-
brightSolid :: Prism' Fill Unit
198-
brightSolid = nearly (Solid referenceColor) predicate
195+
brightSolidFocus :: Prism' Fill Unit
196+
brightSolidFocus = nearly (Solid referenceColor) predicate
199197
where
200198
referenceColor = Color.graytone 0.8
201199
predicate = case _ of
@@ -209,21 +207,21 @@ brightSolid = nearly (Solid referenceColor) predicate
209207

210208

211209
n1 :: Maybe Unit
212-
n1 = preview brightSolid (Solid Color.white) -- (Just unit)
210+
n1 = preview brightSolidFocus (Solid Color.white) -- (Just unit)
213211

214212
n2 :: Maybe Unit
215-
n2 = preview brightSolid (Solid Color.black) -- Nothing
213+
n2 = preview brightSolidFocus (Solid Color.black) -- Nothing
216214

217215
n3 :: Maybe Unit
218-
n3 = preview brightSolid NoFill -- Nothing
216+
n3 = preview brightSolidFocus NoFill -- Nothing
219217

220218

221219
-- So you probably want to use `is` or `isn't`:
222220

223221
n4 :: Boolean
224-
n4 = is brightSolid (Solid Color.white) :: Boolean -- true
222+
n4 = is brightSolidFocus (Solid Color.white) :: Boolean -- true
225223

226224
-- You can recover the reference value with `review`:
227225

228226
n5 :: Fill
229-
n5 = review brightSolid unit -- (Solid rgba 204 204 204 1.0)
227+
n5 = review brightSolidFocus unit -- (Solid rgba 204 204 204 1.0)

0 commit comments

Comments
 (0)