-
Notifications
You must be signed in to change notification settings - Fork 272
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
25 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' |