File: Aeson.hs

package info (click to toggle)
haskell-lens 5.3.5-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 2,060 kB
  • sloc: haskell: 16,249; ansic: 20; makefile: 8
file content (29 lines) | stat: -rw-r--r-- 666 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE Rank2Types #-}
-- |
-- This is a small example of how to construct a projection for a third-party library like
-- @aeson@.
--
-- To test this:
--
-- > doctest Aeson.hs
module Aeson where

import Control.Lens
import Data.Aeson
import Data.ByteString.Lazy (ByteString)

-- $setup
-- >>> import Control.Lens

-- |
-- >>> review aeson 5
-- "5"
-- >>> [1,2,3]^.re aeson
-- "[1,2,3]"
-- >>> let intPair = simple :: Iso' (Int,Int) (Int, Int)
-- >>> aeson.intPair.both +~ 2 $ (2,3)^.re aeson
-- "[4,5]"
aeson, aeson' :: (FromJSON a, ToJSON a) => Prism' ByteString a
aeson  = prism' encode decode
aeson' = prism' encode decode'