Skip to content

Commit a06b051

Browse files
committed
Remove compiler warnings
1 parent 83b58b1 commit a06b051

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

examples/src/PrismsForSumTypes.purs

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,26 @@ module PrismsForSumTypes where
77
import Data.Maybe
88
99
import Data.Lens
10-
import Data.Lens as Lens
1110
import Data.Lens.Prism
1211
import Color as Color
1312
import Data.Record.ShowRecord (showRecord)
1413
import PrismsForSumTypes
15-
import Data.Number.Approximate
1614
1715
-}
1816

1917
import Prelude
20-
import Data.Maybe
21-
import Data.Either
18+
import Data.Lens (Prism', is, isn't, nearly, only, preview, prism, prism', review)
2219

23-
import Data.Lens
24-
import Data.Lens as Lens
2520
import Color (Color)
2621
import Color as Color
27-
import Data.Tuple
28-
import Data.Generic.Rep
22+
23+
import Data.Generic.Rep (class Generic)
2924
import Data.Generic.Rep.Eq as GEq
3025
import Data.Generic.Rep.Show as GShow
3126
import Data.Record.ShowRecord (showRecord)
32-
import Data.Number.Approximate
27+
import Data.Maybe (Maybe(..), maybe)
28+
import Data.Either (Either(..))
29+
3330

3431
{- The types in question -}
3532

@@ -95,6 +92,7 @@ solidFocus = prism' constructor focus
9592

9693
-- In real life, you might abbreviate the above to this:
9794

95+
solidFocus' :: Prism' Fill Color
9896
solidFocus' = prism' Solid case _ of
9997
Solid color -> Just color
10098
_ -> Nothing
@@ -103,17 +101,24 @@ solidFocus' = prism' Solid case _ of
103101

104102
-- After building a prism, you focus in on a color with `preview`:
105103

104+
s1 :: Maybe Color
106105
s1 = preview solidFocus (Solid Color.white) -- (Just rgba 255 255 255 1.0)
106+
107+
s2 :: Maybe Color
107108
s2 = preview solidFocus fillRadial -- Nothing
108109

109110
-- ... or you can create a Fill from a color with `review`:
110111

112+
s3 :: Fill
111113
s3 = review solidFocus Color.white
112114
-- (Solid rgba 255 255 255 1.0)
113115

114116
-- ... or you can ask whether a given value matches the prism:
115117

118+
s4 :: Boolean
116119
s4 = is solidFocus fillWhite :: Boolean -- true
120+
121+
s5 :: Boolean
117122
s5 = isn't solidFocus fillWhite :: Boolean -- false
118123

119124

@@ -147,22 +152,30 @@ linearFocus = prism constructor focus
147152

148153
-- Even though made differently, this prism is used the same way:
149154

155+
l1 :: String
150156
l1 = preview linearFocus fillBlackToWhite # maybe "!" showRecord
151157
-- "{ color1: rgba 0 0 0 1.0, color2: rgba 255 255 255 1.0, percent: (3.3%) }"
152158

159+
l2 :: Fill
153160
l2 = review linearFocus { color1 : Color.black
154161
, color2 : Color.white
155162
, percent : Percent 33.3
156163
}
157164

158165
{- Constructing more specific prisms -}
159166

160-
-- `only` is used to look for a specific value:
167+
-- `only` is used to check for a specific value:
161168

169+
whiteSolid :: Prism' Fill Unit
162170
whiteSolid = only (Solid Color.white)
163171

172+
o1 :: Boolean
164173
o1 = is whiteSolid (Solid Color.white) :: Boolean -- true
174+
175+
o2 :: Boolean
165176
o2 = is whiteSolid (Solid Color.black) :: Boolean -- false
177+
178+
o3 :: Boolean
166179
o3 = is whiteSolid fillRadial :: Boolean -- false
167180

168181

@@ -189,17 +202,22 @@ brightSolid = nearly (Solid referenceColor) predicate
189202
-- from `preview`:
190203

191204

205+
n1 :: Maybe Unit
192206
n1 = preview brightSolid (Solid Color.white) -- (Just unit)
193207

208+
n2 :: Maybe Unit
194209
n2 = preview brightSolid (Solid Color.black) -- Nothing
195210

211+
n3 :: Maybe Unit
196212
n3 = preview brightSolid NoFill -- Nothing
197213

198214

199215
-- So you probably want to use `is` or `isn't`:
200216

217+
n4 :: Boolean
201218
n4 = is brightSolid (Solid Color.white) :: Boolean -- true
202219

203220
-- You can recover the reference value with `review`:
204221

222+
n5 :: Fill
205223
n5 = review brightSolid unit -- (Solid rgba 204 204 204 1.0)

0 commit comments

Comments
 (0)