···142142 -> (b -> b)
143143 -> a
144144 -> a
145145-modify =
146146- error "todo: modify"
145145+modify (Lens s g) f a =
146146+ s a (f (g a))
147147148148-- | An alias for @modify@.
149149(%~) ::
···172172 -> b
173173 -> a
174174 -> a
175175-(.~) =
176176- error "todo: (.~)"
175175+(.~) l =
176176+ modify l . const
177177178178infixl 5 .~
179179···193193 -> (b -> f b)
194194 -> a
195195 -> f a
196196-fmodify =
197197- error "todo: fmodify"
196196+fmodify (Lens s g) f a =
197197+ fmap (s a) (f (g a))
198198199199-- |
200200--
···209209 -> f b
210210 -> a
211211 -> f a
212212-(|=) =
213213- error "todo: (|=)"
212212+(|=) l =
213213+ fmodify l . const
214214215215infixl 5 |=
216216···227227fstL ::
228228 Lens (x, y) x
229229fstL =
230230- error "todo: fstL"
230230+ Lens
231231+ (\(_, y) x -> (x, y))
232232+ (\(x, _) -> x)
231233232234-- |
233235--
···242244sndL ::
243245 Lens (x, y) y
244246sndL =
245245- error "todo: sndL"
247247+ Lens
248248+ (\(x, _) y -> (x, y))
249249+ (\(_, y) -> y)
246250247251-- |
248252--
···267271 Ord k =>
268272 k
269273 -> Lens (Map k v) (Maybe v)
270270-mapL =
271271- error "todo: mapL"
274274+mapL k =
275275+ Lens
276276+ (maybe . Map.delete k <*> (flip (Map.insert k)))
277277+ (Map.lookup k)
272278273279-- |
274280--
···293299 Ord k =>
294300 k
295301 -> Lens (Set k) Bool
296296-setL =
297297- error "todo: setL"
302302+setL k =
303303+ Lens
304304+ (bool . Set.delete k <*> Set.insert k)
305305+ (Set.member k)
298306299307-- |
300308--
···307315 Lens b c
308316 -> Lens a b
309317 -> Lens a c
310310-compose =
311311- error "todo: compose"
318318+compose (Lens s1 g1) (Lens s2 g2) =
319319+ Lens
320320+ (\a -> s2 a . s1 (g2 a))
321321+ (g1 . g2)
312322313323-- | An alias for @compose@.
314324(|.) ::
···330340identity ::
331341 Lens a a
332342identity =
333333- error "todo: identity"
343343+ Lens
344344+ (const id)
345345+ id
334346335347-- |
336348--
···343355 Lens a b
344356 -> Lens c d
345357 -> Lens (a, c) (b, d)
346346-product =
347347- error "todo: product"
358358+product (Lens s1 g1) (Lens s2 g2) =
359359+ Lens
360360+ (\(a, c) (b, d) -> (s1 a b, s2 c d))
361361+ (\(a, c) -> (g1 a, g2 c))
348362349363-- | An alias for @product@.
350364(***) ::
···373387 Lens a x
374388 -> Lens b x
375389 -> Lens (Either a b) x
376376-choice =
377377- error "todo: choice"
390390+choice (Lens s1 g1) (Lens s2 g2) =
391391+ Lens
392392+ (\e x -> either (\a -> Left (s1 a x)) (\b -> Right (s2 b x)) e)
393393+ (either g1 g2)
378394379395-- | An alias for @choice@.
380396(|||) ::
···462478 Person
463479 -> String
464480getSuburb =
465465- error "todo: getSuburb"
481481+ get (suburbL |. addressL)
466482467483-- |
468484--
···476492 -> String
477493 -> Person
478494setStreet =
479479- error "todo: setStreet"
495495+ set (streetL |. addressL)
480496481497-- |
482498--
···489505 (Person, Locality)
490506 -> (Int, String)
491507getAgeAndCountry =
492492- error "todo: getAgeAndCountry"
508508+ get (ageL *** countryL)
493509494510-- |
495511--
···501517setCityAndLocality ::
502518 (Person, Address) -> (String, Locality) -> (Person, Address)
503519setCityAndLocality =
504504- error "todo: setCityAndLocality"
520520+ set (cityL |. localityL |. addressL *** localityL)
505521506522-- |
507523--
···514530 Either Address Locality
515531 -> String
516532getSuburbOrCity =
517517- error "todo: getSuburbOrCity"
533533+ get (suburbL ||| cityL)
518534519535-- |
520536--
···528544 -> String
529545 -> Either Person Locality
530546setStreetOrState =
531531- error "todo: setStreetOrState"
547547+ set (streetL |. addressL ||| stateL)
532548533549-- |
534550--
···541557 Person
542558 -> Person
543559modifyCityUppercase =
544544- error "todo: modifyCityUppercase"
560560+ cityL |. localityL |. addressL %~ map toUpper
+98-72
src/Lets/Lens/Lens.hs
···110110 (a -> b)
111111 -> t a
112112 -> t b
113113-fmapT =
114114- error "todo: fmapT"
113113+fmapT f =
114114+ getIdentity . traverse (Identity . f)
115115116116-- | Let's refactor out the call to @traverse@ as an argument to @fmapT@.
117117over ::
···119119 -> (a -> b)
120120 -> s
121121 -> t
122122-over =
123123- error "todo: over"
122122+over t f =
123123+ getIdentity . t (Identity . f)
124124125125-- | Here is @fmapT@ again, passing @traverse@ to @over@.
126126fmapTAgain ::
···129129 -> t a
130130 -> t b
131131fmapTAgain =
132132- error "todo: fmapTAgain"
132132+ over traverse
133133134134-- | Let's create a type-alias for this type of function.
135135type Set s t a b =
···142142sets ::
143143 ((a -> b) -> s -> t)
144144 -> Set s t a b
145145-sets =
146146- error "todo: sets"
145145+sets t f =
146146+ Identity . t (getIdentity . f)
147147148148mapped ::
149149 Functor f =>
150150 Set (f a) (f b) a b
151151mapped =
152152- error "todo: mapped"
152152+ sets fmap
153153154154set ::
155155 Set s t a b
156156 -> s
157157 -> b
158158 -> t
159159-set =
160160- error "todo: set"
159159+set t s b =
160160+ over t (const b) s
161161162162----
163163···169169 (a -> b)
170170 -> t a
171171 -> b
172172-foldMapT =
173173- error "todo: foldMapT"
172172+foldMapT f =
173173+ getConst . traverse (Const . f)
174174175175-- | Let's refactor out the call to @traverse@ as an argument to @foldMapT@.
176176foldMapOf ::
···178178 -> (a -> r)
179179 -> s
180180 -> r
181181-foldMapOf =
182182- error "todo: foldMapOf"
181181+foldMapOf t f =
182182+ getConst . t (Const . f)
183183184184-- | Here is @foldMapT@ again, passing @traverse@ to @foldMapOf@.
185185foldMapTAgain ::
···188188 -> t a
189189 -> b
190190foldMapTAgain =
191191- error "todo: foldMapTAgain"
191191+ foldMapOf traverse
192192193193-- | Let's create a type-alias for this type of function.
194194type Fold s t a b =
···205205 -> (a -> Const b a)
206206 -> s
207207 -> Const t s
208208-folds =
209209- error "todo: folds"
208208+folds t f =
209209+ Const . t (getConst . f)
210210211211folded ::
212212 Foldable f =>
213213 Fold (f a) (f a) a a
214214folded =
215215- error "todo: folded"
215215+ folds foldMap
216216217217----
218218···226226 Get a s a
227227 -> s
228228 -> a
229229-get =
230230- error "todo: get"
229229+get t =
230230+ getConst . t Const
231231232232----
233233···242242-- | Traverse both sides of a pair.
243243both ::
244244 Traversal (a, a) (b, b) a b
245245-both =
246246- error "todo: both"
245245+both f (a, b) =
246246+ (,) <$> f a <*> f b
247247248248-- | Traverse the left side of @Either@.
249249traverseLeft ::
250250 Traversal (Either a x) (Either b x) a b
251251-traverseLeft =
252252- error "todo: traverseLeft"
251251+traverseLeft f (Left a) =
252252+ Left <$> f a
253253+traverseLeft _ (Right x) =
254254+ pure (Right x)
253255254256-- | Traverse the right side of @Either@.
255257traverseRight ::
256258 Traversal (Either x a) (Either x b) a b
257257-traverseRight =
258258- error "todo: traverseRight"
259259+traverseRight _ (Left x) =
260260+ pure (Left x)
261261+traverseRight f (Right a) =
262262+ Right <$> f a
259263260264type Traversal' a b =
261265 Traversal a a b b
···286290_Left ::
287291 Prism (Either a x) (Either b x) a b
288292_Left =
289289- error "todo: _Left"
293293+ dimap (either Right (Left . Right)) (either pure (fmap Left)) . right
290294291295_Right ::
292296 Prism (Either x a) (Either x b) a b
293297_Right =
294294- error "todo: _Right"
298298+ dimap (either (Left . Left) Right) (either pure (fmap Right)) . right
295299296300prism ::
297301 (b -> t)
298302 -> (s -> Either t a)
299303 -> Prism s t a b
300300-prism =
301301- error "todo: prism"
304304+prism to fr =
305305+ dimap fr (either pure (fmap to)) . right
302306303307_Just ::
304308 Prism (Maybe a) (Maybe b) a b
305309_Just =
306306- error "todo: _Just"
310310+ prism
311311+ Just
312312+ (maybe (Left Nothing) Right)
307313308314_Nothing ::
309315 Prism (Maybe a) (Maybe a) () ()
310316_Nothing =
311311- error "todo: _Nothing"
317317+ prism
318318+ (\() -> Nothing)
319319+ (maybe (Right ()) (Left . Just))
312320313321setP ::
314322 Prism s t a b
315323 -> s
316324 -> Either t a
317317-setP =
318318- error "todo: setP"
325325+setP p =
326326+ either Right Left . p Left
319327320328getP ::
321329 Prism s t a b
322330 -> b
323331 -> t
324324-getP =
325325- error "todo: getP"
332332+getP p =
333333+ getIdentity . getTagged . p . Tagged . Identity
326334327335type Prism' a b =
328336 Prism a a b b
···345353 -> (a -> b)
346354 -> s
347355 -> t
348348-modify =
349349- error "todo: modify"
356356+modify r f =
357357+ getIdentity . r (Identity . f)
350358351359-- | An alias for @modify@.
352360(%~) ::
···375383 -> b
376384 -> s
377385 -> t
378378-(.~) =
379379- error "todo: (.~)"
386386+(.~) l =
387387+ modify l . const
380388381389infixl 5 .~
382390···396404 -> (a -> f b)
397405 -> s
398406 -> f t
399399-fmodify =
400400- error "todo: fmodify"
407407+fmodify l =
408408+ l
401409402410-- |
403411--
···412420 -> f b
413421 -> s
414422 -> f t
415415-(|=) =
416416- error "todo: (|=)"
423423+(|=) l =
424424+ fmodify l . const
417425418426infixl 5 |=
419427···423431-- (30,"abc")
424432fstL ::
425433 Lens (a, x) (b, x) a b
426426-fstL =
427427- error "todo: fstL"
434434+fstL p (x, y) =
435435+ fmap (\x' -> (x', y)) (p x)
428436429437-- |
430438--
···432440-- (13,"abcdef")
433441sndL ::
434442 Lens (x, a) (x, b) a b
435435-sndL =
436436- error "todo: sndL"
443443+sndL p (x, y) =
444444+ fmap (\y' -> (x, y')) (p y)
437445438446-- |
439447--
···458466 Ord k =>
459467 k
460468 -> Lens (Map k v) (Map k v) (Maybe v) (Maybe v)
461461-mapL =
462462- error "todo: mapL"
469469+mapL k p m =
470470+ let z = Map.lookup k m
471471+ in fmap (\y -> case y of
472472+ Just v -> Map.insert k v m
473473+ Nothing -> case z of
474474+ Just _ -> Map.delete k m
475475+ Nothing -> m) (p z)
463476464477-- |
465478--
···484497 Ord k =>
485498 k
486499 -> Lens (Set.Set k) (Set.Set k) Bool Bool
487487-setL =
488488- error "todo: setL"
500500+setL k =
501501+ (\p s -> fmap (\b -> bool Set.delete Set.insert b k s) (p (Set.member k s)))
489502490503-- |
491504--
···498511 Lens s t a b
499512 -> Lens q r s t
500513 -> Lens q r a b
501501-compose =
502502- error "todo: compose"
514514+compose r1 r2 =
515515+ r2 . r1
503516504517-- | An alias for @compose@.
505518(|.) ::
···521534identity ::
522535 Lens a b a b
523536identity =
524524- error "todo: identity"
537537+ id
525538526539-- |
527540--
···534547 Lens s t a b
535548 -> Lens q r c d
536549 -> Lens (s, q) (t, r) (a, c) (b, d)
537537-product =
538538- error "todo: product"
550550+product r1 r2 p (a, c) =
551551+ getAlongsideRight (r2 (\b2 -> AlongsideRight (
552552+ getAlongsideLeft (r1 (\b1 -> AlongsideLeft (
553553+ p (b1,b2))) a))) c)
539554540555-- | An alias for @product@.
541556(***) ::
···564579 Lens s t a b
565580 -> Lens q r a b
566581 -> Lens (Either s q) (Either t r) a b
567567-choice =
568568- error "todo: choice"
582582+choice r1 r2 =
583583+584584+ (\p e -> case e of
585585+ Left a -> fmap Left (r1 p a)
586586+ Right b -> fmap Right (r2 p b))
569587570588-- | An alias for @choice@.
571589(|||) ::
···649667 Person
650668 -> String
651669getSuburb =
652652- error "todo: getSuburb"
670670+ get (suburbL |. addressL)
653671654672-- |
655673--
···663681 -> String
664682 -> Person
665683setStreet =
666666- error "todo: setStreet"
684684+ set (streetL |. addressL)
667685668686-- |
669687--
···676694 (Person, Locality)
677695 -> (Int, String)
678696getAgeAndCountry =
679679- error "todo: getAgeAndCountry"
697697+ get (ageL *** countryL)
680698681699-- |
682700--
···688706setCityAndLocality ::
689707 (Person, Address) -> (String, Locality) -> (Person, Address)
690708setCityAndLocality =
691691- error "todo: setCityAndLocality"
709709+ set (cityL |. localityL |. addressL *** localityL)
692710693711-- |
694712--
···701719 Either Address Locality
702720 -> String
703721getSuburbOrCity =
704704- error "todo: getSuburbOrCity"
722722+ get (suburbL ||| cityL)
705723706724-- |
707725--
···715733 -> String
716734 -> Either Person Locality
717735setStreetOrState =
718718- error "todo: setStreetOrState"
736736+ set (streetL |. addressL ||| stateL)
719737720738-- |
721739--
···728746 Person
729747 -> Person
730748modifyCityUppercase =
731731- error "todo: modifyCityUppercase"
749749+ cityL |. localityL |. addressL %~ map toUpper
732750733751-- |
734752--
···741759 IntAnd [a]
742760 -> IntAnd Bool
743761modifyIntAndLengthEven =
744744- error "todo: modifyIntAndLengthEven"
762762+ intAndL %~ even . length
745763746764----
747765···751769-- Locality "ABC" "DEF" "GHI"
752770traverseLocality ::
753771 Traversal' Locality String
754754-traverseLocality =
755755- error "todo: traverseLocality"
772772+traverseLocality f (Locality c t y) =
773773+ Locality <$> f c <*> f t <*> f y
756774757775-- |
758776--
···764782intOrIntP ::
765783 Prism' (IntOr a) Int
766784intOrIntP =
767767- error "todo: intOrIntP"
785785+ prism
786786+ IntOrIs
787787+ (\i -> case i of
788788+ IntOrIs n -> Right n
789789+ IntOrIsNot a -> Left (IntOrIsNot a))
768790769791intOrP ::
770792 Prism (IntOr a) (IntOr b) a b
771793intOrP =
772772- error "todo: intOrP"
794794+ prism
795795+ IntOrIsNot
796796+ (\i -> case i of
797797+ IntOrIs n -> Left (IntOrIs n)
798798+ IntOrIsNot a -> Right a)
773799774800-- |
775801--
···785811 IntOr [a]
786812 -> IntOr Bool
787813intOrLengthEven =
788788- error "todo: intOrLengthEven"
814814+ over intOrP (even . length)
+42-26
src/Lets/OpticPolyLens.hs
···123123 -> (a -> b)
124124 -> s
125125 -> t
126126-modify =
127127- error "todo: modify"
126126+modify (Lens r) f =
127127+ getIdentity . r (Identity . f)
128128129129-- | An alias for @modify@.
130130(%~) ::
···153153 -> b
154154 -> s
155155 -> t
156156-(.~) =
157157- error "todo: (.~)"
156156+(.~) l =
157157+ modify l . const
158158159159infixl 5 .~
160160···174174 -> (a -> f b)
175175 -> s
176176 -> f t
177177-fmodify =
178178- error "todo: fmodify"
177177+fmodify (Lens r) f a =
178178+ r f a
179179180180-- |
181181--
···190190 -> f b
191191 -> s
192192 -> f t
193193-(|=) =
194194- error "todo: (|=)"
193193+(|=) l =
194194+ fmodify l . const
195195196196infixl 5 |=
197197···208208fstL ::
209209 Lens (a, x) (b, x) a b
210210fstL =
211211- error "todo: fstL"
211211+ Lens
212212+ (\p (x, y) -> fmap (\x' -> (x', y)) (p x))
212213213214-- |
214215--
···223224sndL ::
224225 Lens (x, a) (x, b) a b
225226sndL =
226226- error "todo: sndL"
227227+ Lens
228228+ (\p (x, y) -> fmap (\y' -> (x, y')) (p y))
227229228230-- |
229231--
···248250 Ord k =>
249251 k
250252 -> Lens (Map k v) (Map k v) (Maybe v) (Maybe v)
251251-mapL =
252252- error "todo: mapL"
253253+mapL k =
254254+ Lens
255255+ (\p m -> let z = Map.lookup k m
256256+ in fmap (\y -> case y of
257257+ Just v -> Map.insert k v m
258258+ Nothing -> case z of
259259+ Just _ -> Map.delete k m
260260+ Nothing -> m) (p z))
253261254262-- |
255263--
···274282 Ord k =>
275283 k
276284 -> Lens (Set k) (Set k) Bool Bool
277277-setL =
278278- error "todo: setL"
285285+setL k =
286286+ Lens
287287+ (\p s -> fmap (\b -> bool Set.delete Set.insert b k s) (p (Set.member k s)))
279288280289-- |
281290--
···288297 Lens s t a b
289298 -> Lens q r s t
290299 -> Lens q r a b
291291-compose =
292292- error "todo: compose"
300300+compose (Lens r1) (Lens r2) =
301301+ Lens
302302+ (r2 . r1)
293303294304-- | An alias for @compose@.
295305(|.) ::
···311321identity ::
312322 Lens a b a b
313323identity =
314314- error "todo: identity"
324324+ Lens
325325+ id
315326316327-- |
317328--
···324335 Lens s t a b
325336 -> Lens q r c d
326337 -> Lens (s, q) (t, r) (a, c) (b, d)
327327-product =
328328- error "todo: product"
338338+product (Lens r1) (Lens r2) =
339339+ Lens
340340+ (\p (a, c) -> getAlongsideRight (r2 (\b2 -> AlongsideRight (
341341+ getAlongsideLeft (r1 (\b1 -> AlongsideLeft (
342342+ p (b1,b2))) a))) c))
329343330344-- | An alias for @product@.
331345(***) ::
···354368 Lens s t a b
355369 -> Lens q r a b
356370 -> Lens (Either s q) (Either t r) a b
357357-choice =
358358- error "todo: choice"
371371+choice (Lens r1) (Lens r2) =
372372+ Lens
373373+ (\p e -> case e of
374374+ Left a -> fmap Left (r1 p a)
375375+ Right b -> fmap Right (r2 p b))
359376360377-- | An alias for @choice@.
361378(|||) ::
···450467 Person
451468 -> String
452469getSuburb =
453453- error "todo: getSuburb"
454454-470470+ get (suburbL |. addressL)
455471456472-- |
457473--
···465481 -> String
466482 -> Person
467483setStreet =
468468- error "todo: setStreet"
484484+ set (streetL |. addressL)
469485470486-- |
471487--
···478494 (Person, Locality)
479495 -> (Int, String)
480496getAgeAndCountry =
481481- error "todo: getAgeAndCountry"
497497+ get (ageL *** countryL)
482498483499-- |
484500--
···490506setCityAndLocality ::
491507 (Person, Address) -> (String, Locality) -> (Person, Address)
492508setCityAndLocality =
493493- error "todo: setCityAndLocality"
509509+ set (cityL |. localityL |. addressL *** localityL)
494510495511-- |
496512--
+51-36
src/Lets/StoreLens.hs
···7777 (a -> b)
7878 -> Store s a
7979 -> Store s b
8080-mapS =
8181- error "todo: mapS"
8080+mapS f (Store s g) =
8181+ Store (f . s) g
82828383duplicateS ::
8484 Store s a
8585 -> Store s (Store s a)
8686-duplicateS =
8787- error "todo: duplicateS"
8686+duplicateS (Store s g) =
8787+ Store (Store s) g
88888989extendS ::
9090 (Store s a -> b)
9191 -> Store s a
9292 -> Store s b
9393-extendS =
9494- error "todo: extendS"
9393+extendS f =
9494+ mapS f . duplicateS
95959696extractS ::
9797 Store s a
9898 -> a
9999-extractS =
100100- error "todo: extractS"
9999+extractS (Store s g) =
100100+ s g
101101102102----
103103···190190 -> (b -> b)
191191 -> a
192192 -> a
193193-modify =
194194- error "todo: modify"
193193+modify (Lens r) f a =
194194+ let Store s g = r a
195195+ in s (f g)
195196196197-- | An alias for @modify@.
197198(%~) ::
···220221 -> b
221222 -> a
222223 -> a
223223-(.~) =
224224- error "todo: (.~)"
224224+(.~) l =
225225+ modify l . const
225226226227infixl 5 .~
227228···241242 -> (b -> f b)
242243 -> a
243244 -> f a
244244-fmodify =
245245- error "todo: fmodify"
245245+fmodify (Lens r) f a =
246246+ let Store s g = r a
247247+ in fmap s (f g)
246248247249-- |
248250--
···257259 -> f b
258260 -> a
259261 -> f a
260260-(|=) =
261261- error "todo: (|=)"
262262+(|=) l =
263263+ fmodify l . const
262264263265infixl 5 |=
264266···275277fstL ::
276278 Lens (x, y) x
277279fstL =
278278- error "todo: fstL"
280280+ Lens
281281+ (\(x, y) -> Store (\x' -> (x', y)) x)
279282280283-- |
281284--
···290293sndL ::
291294 Lens (x, y) y
292295sndL =
293293- error "todo: sndL"
296296+ Lens
297297+ (\(x, y) -> Store (\y' -> (x, y')) y)
294298295299-- |
296300--
···315319 Ord k =>
316320 k
317321 -> Lens (Map k v) (Maybe v)
318318-mapL =
319319- error "todo: mapL"
322322+mapL k =
323323+ Lens
324324+ (Store <$> (maybe . Map.delete k <*> (flip (Map.insert k))) <*> Map.lookup k)
320325321326-- |
322327--
···341346 Ord k =>
342347 k
343348 -> Lens (Set k) Bool
344344-setL =
345345- error "todo: setL"
349349+setL k =
350350+ Lens
351351+ (Store <$> (bool . Set.delete k <*> Set.insert k) <*> Set.member k)
346352347353-- |
348354--
···355361 Lens b c
356362 -> Lens a b
357363 -> Lens a c
358358-compose =
359359- error "todo: compose"
364364+compose (Lens r1) (Lens r2) =
365365+ Lens
366366+ (\a -> let Store s2 g2 = r2 a
367367+ Store s1 g1 = r1 g2
368368+ in Store (s2 . s1) g1)
360369361370-- | An alias for @compose@.
362371(|.) ::
···378387identity ::
379388 Lens a a
380389identity =
381381- error "todo: identity"
390390+ Lens (Store id)
382391383392-- |
384393--
···391400 Lens a b
392401 -> Lens c d
393402 -> Lens (a, c) (b, d)
394394-product =
395395- error "todo: product"
403403+product (Lens r1) (Lens r2) =
404404+ Lens (\(a, c) ->
405405+ let Store s1 g1 = r1 a
406406+ Store s2 g2 = r2 c
407407+ in Store (\(b, d) -> (s1 b, s2 d)) (g1, g2))
396408397409-- | An alias for @product@.
398410(***) ::
···421433 Lens a x
422434 -> Lens b x
423435 -> Lens (Either a b) x
424424-choice =
425425- error "todo: choice"
436436+choice (Lens r1) (Lens r2) =
437437+ Lens (\e ->
438438+ case e of
439439+ Left a -> mapS Left (r1 a)
440440+ Right b -> mapS Right (r2 b))
426441427442-- | An alias for @choice@.
428443(|||) ::
···510525 Person
511526 -> String
512527getSuburb =
513513- error "todo: getSuburb"
528528+ get (suburbL |. addressL)
514529515530-- |
516531--
···524539 -> String
525540 -> Person
526541setStreet =
527527- error "todo: setStreet"
542542+ set (streetL |. addressL)
528543529544-- |
530545--
···537552 (Person, Locality)
538553 -> (Int, String)
539554getAgeAndCountry =
540540- error "todo: getAgeAndCountry"
555555+ get (ageL *** countryL)
541556542557-- |
543558--
···549564setCityAndLocality ::
550565 (Person, Address) -> (String, Locality) -> (Person, Address)
551566setCityAndLocality =
552552- error "todo: setCityAndLocality"
567567+ set (cityL |. localityL |. addressL *** localityL)
553568554569-- |
555570--
···562577 Either Address Locality
563578 -> String
564579getSuburbOrCity =
565565- error "todo: getSuburbOrCity"
580580+ get (suburbL ||| cityL)
566581567582-- |
568583--
···576591 -> String
577592 -> Either Person Locality
578593setStreetOrState =
579579- error "todo: setStreetOrState"
594594+ set (streetL |. addressL ||| stateL)
580595581596-- |
582597--
···589604 Person
590605 -> Person
591606modifyCityUppercase =
592592- error "todo: modifyCityUppercase"
607607+ cityL |. localityL |. addressL %~ map toUpper