Created
August 2, 2017 03:07
-
-
Save rahulmutt/d9d64c45e58b61628a4fb6a6852ecc52 to your computer and use it in GitHub Desktop.
Lens Example in Eta
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main where | |
import Control.Lens | |
import Data.Aeson | |
import Data.Aeson.Lens | |
import Data.Aeson.Encode.Pretty | |
import qualified Data.ByteString.Lazy.Char8 as BS | |
main :: IO () | |
main = do | |
let json = "[{\"clicks\":1},{\"clicks\":2},{\"clicks\":3}]" | |
json' = json & (values . members . _Integral) %~ (+50) | |
case decode json' :: Maybe Value of | |
Just value -> putStrLn $ BS.unpack $ encodePretty value | |
Nothing -> putStrLn "Bad JSON!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment