Skip to content

Commit

Permalink
Add wat operator
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-marie committed Dec 17, 2014
1 parent e306e60 commit c4a00d8
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/Data/Aeson/RoundTrip.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Control.Isomorphism.Partial
import Control.Lens hiding (Iso)
import qualified Control.Lens as L
import Control.Monad (guard, liftM2, mplus, (>=>))
import Data.Monoid
import Data.Aeson
import Data.Aeson.Lens
import Data.HashMap.Strict (union)
Expand Down Expand Up @@ -62,6 +63,14 @@ class Syntax s => JsonSyntax s where
is :: (JsonSyntax s, Eq a) => s a -> a -> s ()
is s a = demote (prism' (const a) (guard . (a ==))) <$> s


-- | With Arbitrary Thing: Given a thing, ensure that it is always included on
-- the way "back" from JSON, but never ends up in the JSON document.
--
-- This is almost like pure, going one way.
wat :: JsonSyntax s => a -> s a
wat a = demote (prism' (const $ Object mempty) (const $ Just a)) <$> value

-- | Un-/parse from within a field in a JSON object.
jsonField
:: JsonSyntax s
Expand Down

0 comments on commit c4a00d8

Please sign in to comment.