From c4a00d8899161feeeb440fe6055b077516d63250 Mon Sep 17 00:00:00 2001 From: Christian Marie Date: Wed, 17 Dec 2014 16:06:55 +1100 Subject: [PATCH] Add wat operator --- lib/Data/Aeson/RoundTrip.hs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/Data/Aeson/RoundTrip.hs b/lib/Data/Aeson/RoundTrip.hs index f8277a4..2224305 100644 --- a/lib/Data/Aeson/RoundTrip.hs +++ b/lib/Data/Aeson/RoundTrip.hs @@ -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) @@ -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