src: Lets: GetSetLens: Implement the examples

Signed-off-by: Sanchayan Maity <maitysanchayan@gmail.com>
This commit is contained in:
Sanchayan Maity 2019-02-10 19:31:13 +05:30
parent 1b68f0617f
commit 5186970bb8

View file

@ -466,8 +466,7 @@ addressL =
getSuburb :: getSuburb ::
Person Person
-> String -> String
getSuburb = getSuburb = get $ (compose suburbL addressL)
error "todo: getSuburb"
-- | -- |
-- --
@ -480,8 +479,7 @@ setStreet ::
Person Person
-> String -> String
-> Person -> Person
setStreet = setStreet = set $ (compose streetL addressL)
error "todo: setStreet"
-- | -- |
-- --
@ -493,8 +491,8 @@ setStreet =
getAgeAndCountry :: getAgeAndCountry ::
(Person, Locality) (Person, Locality)
-> (Int, String) -> (Int, String)
getAgeAndCountry = getAgeAndCountry (person, locality) = (get ageL person,
error "todo: getAgeAndCountry" get countryL locality)
-- | -- |
-- --
@ -505,8 +503,9 @@ getAgeAndCountry =
-- (Person 28 "Mary" (Address "83 Mary Ln" "Maryland" (Locality "Some Other City" "Western Mary" "Maristan")),Address "15 Fred St" "Fredville" (Locality "Mary Mary" "Western Mary" "Maristan")) -- (Person 28 "Mary" (Address "83 Mary Ln" "Maryland" (Locality "Some Other City" "Western Mary" "Maristan")),Address "15 Fred St" "Fredville" (Locality "Mary Mary" "Western Mary" "Maristan"))
setCityAndLocality :: setCityAndLocality ::
(Person, Address) -> (String, Locality) -> (Person, Address) (Person, Address) -> (String, Locality) -> (Person, Address)
setCityAndLocality = setCityAndLocality (person, address) (city, locality) =
error "todo: setCityAndLocality" (set (cityL |. localityL |. addressL) person city,
set localityL address locality)
-- | -- |
-- --
@ -518,8 +517,9 @@ setCityAndLocality =
getSuburbOrCity :: getSuburbOrCity ::
Either Address Locality Either Address Locality
-> String -> String
getSuburbOrCity = getSuburbOrCity = \soc -> case soc of
error "todo: getSuburbOrCity" Left address -> get suburbL address
Right locality -> get cityL locality
-- | -- |
-- --
@ -532,8 +532,9 @@ setStreetOrState ::
Either Person Locality Either Person Locality
-> String -> String
-> Either Person Locality -> Either Person Locality
setStreetOrState = setStreetOrState = \sos -> \ipsos -> case sos of
error "todo: setStreetOrState" Left person -> Left $ set (streetL |. addressL) person ipsos
Right locality -> Right $ set stateL locality ipsos
-- | -- |
-- --
@ -545,5 +546,4 @@ setStreetOrState =
modifyCityUppercase :: modifyCityUppercase ::
Person Person
-> Person -> Person
modifyCityUppercase = modifyCityUppercase = (cityL |. localityL |. addressL) %~ map toUpper
error "todo: modifyCityUppercase"