Permalink
Browse files

added aeson example

  • Loading branch information...
1 parent d23a7d1 commit 742af3dcb51f3d657c600cfb7c8a5f348b8fa7c5 @ekmett committed Sep 12, 2012
Showing with 25 additions and 0 deletions.
  1. +25 −0 examples/Aeson.hs
View
@@ -0,0 +1,25 @@
+{-# 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
+
+-- |
+-- >>> 5^.by aeson
+-- "5"
+-- >>> [1,2,3]^.by aeson
+-- "[1,2,3]"
+-- >>> aeson.both +~ 2 $ (2,3)^.by aeson
+-- "[4,5]"
+aeson, aeson' :: (FromJSON c, ToJSON d) => Projection ByteString ByteString c d
+aeson = projection encode decode
+aeson' = projection encode decode'

0 comments on commit 742af3d

Please sign in to comment.