{-# LANGUAGE CPP #-}
{-# LANGUAGE DefaultSignatures #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE ViewPatterns #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Data.Aeson.Optics
(
AsNumber(..)
, _Integral
, nonNull
, AsValue(..)
, key, members
, nth, values
, IsKey (..)
, AsJSON(..)
, _JSON'
, pattern JSON
, pattern Value_
, pattern Number_
, pattern Double
, pattern Integer
, pattern Integral
, pattern Bool_
, pattern String_
, pattern Null_
, pattern Key_
) where
import Prelude hiding (null)
import Data.Aeson
(FromJSON, Result (..), ToJSON, Value (..), encode, fromJSON, toJSON, decode)
import Data.Scientific (Scientific)
import Data.Text (Text)
import Data.Text.Optics (packed)
import Data.Text.Short (ShortText)
import Data.Vector (Vector)
import Optics.At ()
import Optics.Core
import Optics.Indexed ()
import qualified Data.Aeson.Key as Key
import qualified Data.Aeson.KeyMap as KM
import qualified Data.ByteString as Strict
import qualified Data.ByteString.Lazy as LBS
import qualified Data.Scientific as Scientific
import qualified Data.Text as StrictText
import qualified Data.Text.Encoding as StrictText
import qualified Data.Text.Lazy as LazyText
import qualified Data.Text.Lazy.Encoding as LazyText
class AsNumber t where
_Number :: Prism' t Scientific
default _Number :: AsValue t => Prism' t Scientific
_Number = forall (t :: OpticKind). AsValue t => Prism' t Value
_Valueforall (k :: OpticKind) (l :: OpticKind) (m :: OpticKind)
(is :: IxList) (js :: IxList) (ks :: IxList) (s :: OpticKind)
(t :: OpticKind) (u :: OpticKind) (v :: OpticKind) (a :: OpticKind)
(b :: OpticKind).
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
%forall (t :: OpticKind). AsNumber t => Prism' t Scientific
_Number
{-# INLINE _Number #-}
_Double :: Prism' t Double
_Double = forall (t :: OpticKind). AsNumber t => Prism' t Scientific
_Numberforall (k :: OpticKind) (l :: OpticKind) (m :: OpticKind)
(is :: IxList) (js :: IxList) (ks :: IxList) (s :: OpticKind)
(t :: OpticKind) (u :: OpticKind) (v :: OpticKind) (a :: OpticKind)
(b :: OpticKind).
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
%forall (s :: OpticKind) (a :: OpticKind) (b :: OpticKind)
(t :: OpticKind).
(s -> a) -> (b -> t) -> Iso s t a b
iso forall (a :: OpticKind). RealFloat a => Scientific -> a
Scientific.toRealFloat forall (a :: OpticKind) (b :: OpticKind).
(Real a, Fractional b) =>
a -> b
realToFrac
{-# INLINE _Double #-}
_Integer :: Prism' t Integer
_Integer = forall (t :: OpticKind). AsNumber t => Prism' t Scientific
_Numberforall (k :: OpticKind) (l :: OpticKind) (m :: OpticKind)
(is :: IxList) (js :: IxList) (ks :: IxList) (s :: OpticKind)
(t :: OpticKind) (u :: OpticKind) (v :: OpticKind) (a :: OpticKind)
(b :: OpticKind).
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
%forall (s :: OpticKind) (a :: OpticKind) (b :: OpticKind)
(t :: OpticKind).
(s -> a) -> (b -> t) -> Iso s t a b
iso forall (a :: OpticKind) (b :: OpticKind).
(RealFrac a, Integral b) =>
a -> b
floor forall (a :: OpticKind) (b :: OpticKind).
(Integral a, Num b) =>
a -> b
fromIntegral
{-# INLINE _Integer #-}
instance AsNumber Value where
_Number :: Prism' Value Scientific
_Number = forall (b :: OpticKind) (t :: OpticKind) (s :: OpticKind)
(a :: OpticKind).
(b -> t) -> (s -> Either t a) -> Prism s t a b
prism Scientific -> Value
Number forall (a :: OpticKind) b. (a -> b) -> a -> b
$ \Value
v -> case Value
v of Number Scientific
n -> forall (a :: OpticKind) (b :: OpticKind). b -> Either a b
Right Scientific
n; Value
_ -> forall (a :: OpticKind) (b :: OpticKind). a -> Either a b
Left Value
v
{-# INLINE _Number #-}
instance AsNumber Scientific where
_Number :: Prism' Scientific Scientific
_Number = forall (destKind :: OpticKind) (srcKind :: OpticKind)
(is :: IxList) (s :: OpticKind) (t :: OpticKind) (a :: OpticKind)
(b :: OpticKind).
Is srcKind destKind =>
Optic srcKind is s t a b -> Optic destKind is s t a b
castOptic forall (a :: OpticKind). Iso' a a
simple
{-# INLINE _Number #-}
instance AsNumber Strict.ByteString
instance AsNumber LBS.ByteString
instance AsNumber Text
instance AsNumber LazyText.Text
instance AsNumber String
_Integral :: (AsNumber t, Integral a) => Prism' t a
_Integral :: forall (t :: OpticKind) (a :: OpticKind).
(AsNumber t, Integral a) =>
Prism' t a
_Integral = forall (t :: OpticKind). AsNumber t => Prism' t Scientific
_Number forall (k :: OpticKind) (l :: OpticKind) (m :: OpticKind)
(is :: IxList) (js :: IxList) (ks :: IxList) (s :: OpticKind)
(t :: OpticKind) (u :: OpticKind) (v :: OpticKind) (a :: OpticKind)
(b :: OpticKind).
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% forall (s :: OpticKind) (a :: OpticKind) (b :: OpticKind)
(t :: OpticKind).
(s -> a) -> (b -> t) -> Iso s t a b
iso forall (a :: OpticKind) (b :: OpticKind).
(RealFrac a, Integral b) =>
a -> b
floor forall (a :: OpticKind) (b :: OpticKind).
(Integral a, Num b) =>
a -> b
fromIntegral
{-# INLINE _Integral #-}
nonNull :: Prism' Value Value
nonNull :: Prism' Value Value
nonNull = forall (b :: OpticKind) (t :: OpticKind) (s :: OpticKind)
(a :: OpticKind).
(b -> t) -> (s -> Either t a) -> Prism s t a b
prism forall (a :: OpticKind). a -> a
id (\Value
v -> if forall (k :: OpticKind) (is :: IxList) (s :: OpticKind)
(a :: OpticKind).
Is k An_AffineFold =>
Optic' k is s a -> s -> Bool
isn't forall (t :: OpticKind). AsValue t => Prism' t ()
_Null Value
v then forall (a :: OpticKind) (b :: OpticKind). b -> Either a b
Right Value
v else forall (a :: OpticKind) (b :: OpticKind). a -> Either a b
Left Value
v)
{-# INLINE nonNull #-}
class AsNumber t => AsValue t where
_Value :: Prism' t Value
_Object :: Prism' t (KM.KeyMap Value)
_Object = forall (t :: OpticKind). AsValue t => Prism' t Value
_Valueforall (k :: OpticKind) (l :: OpticKind) (m :: OpticKind)
(is :: IxList) (js :: IxList) (ks :: IxList) (s :: OpticKind)
(t :: OpticKind) (u :: OpticKind) (v :: OpticKind) (a :: OpticKind)
(b :: OpticKind).
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
%forall (b :: OpticKind) (t :: OpticKind) (s :: OpticKind)
(a :: OpticKind).
(b -> t) -> (s -> Either t a) -> Prism s t a b
prism KeyMap Value -> Value
Object (\Value
v -> case Value
v of Object KeyMap Value
o -> forall (a :: OpticKind) (b :: OpticKind). b -> Either a b
Right KeyMap Value
o; Value
_ -> forall (a :: OpticKind) (b :: OpticKind). a -> Either a b
Left Value
v)
_Array :: Prism' t (Vector Value)
_Array = forall (t :: OpticKind). AsValue t => Prism' t Value
_Valueforall (k :: OpticKind) (l :: OpticKind) (m :: OpticKind)
(is :: IxList) (js :: IxList) (ks :: IxList) (s :: OpticKind)
(t :: OpticKind) (u :: OpticKind) (v :: OpticKind) (a :: OpticKind)
(b :: OpticKind).
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
%forall (b :: OpticKind) (t :: OpticKind) (s :: OpticKind)
(a :: OpticKind).
(b -> t) -> (s -> Either t a) -> Prism s t a b
prism Vector Value -> Value
Array (\Value
v -> case Value
v of Array Vector Value
a -> forall (a :: OpticKind) (b :: OpticKind). b -> Either a b
Right Vector Value
a; Value
_ -> forall (a :: OpticKind) (b :: OpticKind). a -> Either a b
Left Value
v)
{-# INLINE _Array #-}
_String :: Prism' t Text
_String = forall (t :: OpticKind). AsValue t => Prism' t Value
_Valueforall (k :: OpticKind) (l :: OpticKind) (m :: OpticKind)
(is :: IxList) (js :: IxList) (ks :: IxList) (s :: OpticKind)
(t :: OpticKind) (u :: OpticKind) (v :: OpticKind) (a :: OpticKind)
(b :: OpticKind).
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
%forall (b :: OpticKind) (t :: OpticKind) (s :: OpticKind)
(a :: OpticKind).
(b -> t) -> (s -> Either t a) -> Prism s t a b
prism Text -> Value
String (\Value
v -> case Value
v of String Text
s -> forall (a :: OpticKind) (b :: OpticKind). b -> Either a b
Right Text
s; Value
_ -> forall (a :: OpticKind) (b :: OpticKind). a -> Either a b
Left Value
v)
{-# INLINE _String #-}
_Bool :: Prism' t Bool
_Bool = forall (t :: OpticKind). AsValue t => Prism' t Value
_Valueforall (k :: OpticKind) (l :: OpticKind) (m :: OpticKind)
(is :: IxList) (js :: IxList) (ks :: IxList) (s :: OpticKind)
(t :: OpticKind) (u :: OpticKind) (v :: OpticKind) (a :: OpticKind)
(b :: OpticKind).
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
%forall (b :: OpticKind) (t :: OpticKind) (s :: OpticKind)
(a :: OpticKind).
(b -> t) -> (s -> Either t a) -> Prism s t a b
prism Bool -> Value
Bool (\Value
v -> case Value
v of Bool Bool
b -> forall (a :: OpticKind) (b :: OpticKind). b -> Either a b
Right Bool
b; Value
_ -> forall (a :: OpticKind) (b :: OpticKind). a -> Either a b
Left Value
v)
{-# INLINE _Bool #-}
_Null :: Prism' t ()
_Null = forall (t :: OpticKind). AsValue t => Prism' t Value
_Value forall (k :: OpticKind) (l :: OpticKind) (m :: OpticKind)
(is :: IxList) (js :: IxList) (ks :: IxList) (s :: OpticKind)
(t :: OpticKind) (u :: OpticKind) (v :: OpticKind) (a :: OpticKind)
(b :: OpticKind).
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% forall (b :: OpticKind) (t :: OpticKind) (s :: OpticKind)
(a :: OpticKind).
(b -> t) -> (s -> Either t a) -> Prism s t a b
prism (forall (a :: OpticKind) (b :: OpticKind). a -> b -> a
const Value
Null) (\Value
v -> case Value
v of Value
Null -> forall (a :: OpticKind) (b :: OpticKind). b -> Either a b
Right (); Value
_ -> forall (a :: OpticKind) (b :: OpticKind). a -> Either a b
Left Value
v)
{-# INLINE _Null #-}
instance AsValue Value where
_Value :: Prism' Value Value
_Value = forall (destKind :: OpticKind) (srcKind :: OpticKind)
(is :: IxList) (s :: OpticKind) (t :: OpticKind) (a :: OpticKind)
(b :: OpticKind).
Is srcKind destKind =>
Optic srcKind is s t a b -> Optic destKind is s t a b
castOptic forall (a :: OpticKind). Iso' a a
simple
{-# INLINE _Value #-}
instance AsValue Strict.ByteString where
_Value :: Prism' ByteString Value
_Value = forall (t :: OpticKind) (a :: OpticKind) (b :: OpticKind).
(AsJSON t, FromJSON a, ToJSON b) =>
Prism t t a b
_JSON
{-# INLINE _Value #-}
instance AsValue LBS.ByteString where
_Value :: Prism' ByteString Value
_Value = forall (t :: OpticKind) (a :: OpticKind) (b :: OpticKind).
(AsJSON t, FromJSON a, ToJSON b) =>
Prism t t a b
_JSON
{-# INLINE _Value #-}
instance AsValue String where
_Value :: Prism' String Value
_Value = Iso' String ByteString
strictUtf8forall (k :: OpticKind) (l :: OpticKind) (m :: OpticKind)
(is :: IxList) (js :: IxList) (ks :: IxList) (s :: OpticKind)
(t :: OpticKind) (u :: OpticKind) (v :: OpticKind) (a :: OpticKind)
(b :: OpticKind).
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
%forall (t :: OpticKind) (a :: OpticKind) (b :: OpticKind).
(AsJSON t, FromJSON a, ToJSON b) =>
Prism t t a b
_JSON
{-# INLINE _Value #-}
instance AsValue Text where
_Value :: Prism' Text Value
_Value = Iso' Text ByteString
strictTextUtf8forall (k :: OpticKind) (l :: OpticKind) (m :: OpticKind)
(is :: IxList) (js :: IxList) (ks :: IxList) (s :: OpticKind)
(t :: OpticKind) (u :: OpticKind) (v :: OpticKind) (a :: OpticKind)
(b :: OpticKind).
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
%forall (t :: OpticKind) (a :: OpticKind) (b :: OpticKind).
(AsJSON t, FromJSON a, ToJSON b) =>
Prism t t a b
_JSON
{-# INLINE _Value #-}
instance AsValue LazyText.Text where
_Value :: Prism' Text Value
_Value = Iso' Text ByteString
lazyTextUtf8forall (k :: OpticKind) (l :: OpticKind) (m :: OpticKind)
(is :: IxList) (js :: IxList) (ks :: IxList) (s :: OpticKind)
(t :: OpticKind) (u :: OpticKind) (v :: OpticKind) (a :: OpticKind)
(b :: OpticKind).
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
%forall (t :: OpticKind) (a :: OpticKind) (b :: OpticKind).
(AsJSON t, FromJSON a, ToJSON b) =>
Prism t t a b
_JSON
{-# INLINE _Value #-}
key :: AsValue t => Key.Key -> AffineTraversal' t Value
key :: forall (t :: OpticKind).
AsValue t =>
Key -> AffineTraversal' t Value
key Key
i = forall (t :: OpticKind). AsValue t => Prism' t (KeyMap Value)
_Object forall (k :: OpticKind) (l :: OpticKind) (m :: OpticKind)
(is :: IxList) (js :: IxList) (ks :: IxList) (s :: OpticKind)
(t :: OpticKind) (u :: OpticKind) (v :: OpticKind) (a :: OpticKind)
(b :: OpticKind).
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% forall (m :: OpticKind).
Ixed m =>
Index m -> Optic' (IxKind m) NoIx m (IxValue m)
ix Key
i
{-# INLINE key #-}
members :: AsValue t => IxTraversal' Key.Key t Value
members :: forall (t :: OpticKind). AsValue t => IxTraversal' Key t Value
members = forall (t :: OpticKind). AsValue t => Prism' t (KeyMap Value)
_Object forall (k :: OpticKind) (l :: OpticKind) (m :: OpticKind)
(is :: IxList) (js :: IxList) (ks :: IxList) (s :: OpticKind)
(t :: OpticKind) (u :: OpticKind) (v :: OpticKind) (a :: OpticKind)
(b :: OpticKind).
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% forall (i :: OpticKind) (f :: OpticKind -> OpticKind)
(a :: OpticKind) (b :: OpticKind).
TraversableWithIndex i f =>
IxTraversal i (f a) (f b) a b
itraversed
{-# INLINE members #-}
nth :: AsValue t => Int -> AffineTraversal' t Value
nth :: forall (t :: OpticKind).
AsValue t =>
Int -> AffineTraversal' t Value
nth Int
i = forall (t :: OpticKind). AsValue t => Prism' t (Vector Value)
_Array forall (k :: OpticKind) (l :: OpticKind) (m :: OpticKind)
(is :: IxList) (js :: IxList) (ks :: IxList) (s :: OpticKind)
(t :: OpticKind) (u :: OpticKind) (v :: OpticKind) (a :: OpticKind)
(b :: OpticKind).
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% forall (m :: OpticKind).
Ixed m =>
Index m -> Optic' (IxKind m) NoIx m (IxValue m)
ix Int
i
{-# INLINE nth #-}
values :: AsValue t => IxTraversal' Int t Value
values :: forall (t :: OpticKind). AsValue t => IxTraversal' Int t Value
values = forall (t :: OpticKind). AsValue t => Prism' t (Vector Value)
_Array forall (k :: OpticKind) (l :: OpticKind) (m :: OpticKind)
(is :: IxList) (js :: IxList) (ks :: IxList) (s :: OpticKind)
(t :: OpticKind) (u :: OpticKind) (v :: OpticKind) (a :: OpticKind)
(b :: OpticKind).
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% forall (i :: OpticKind) (f :: OpticKind -> OpticKind)
(a :: OpticKind) (b :: OpticKind).
TraversableWithIndex i f =>
IxTraversal i (f a) (f b) a b
itraversed
{-# INLINE values #-}
strictUtf8 :: Iso' String Strict.ByteString
strictUtf8 :: Iso' String ByteString
strictUtf8 = forall (t :: OpticKind). IsText t => Iso' String t
packed forall (k :: OpticKind) (l :: OpticKind) (m :: OpticKind)
(is :: IxList) (js :: IxList) (ks :: IxList) (s :: OpticKind)
(t :: OpticKind) (u :: OpticKind) (v :: OpticKind) (a :: OpticKind)
(b :: OpticKind).
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Iso' Text ByteString
strictTextUtf8
strictTextUtf8 :: Iso' StrictText.Text Strict.ByteString
strictTextUtf8 :: Iso' Text ByteString
strictTextUtf8 = forall (s :: OpticKind) (a :: OpticKind) (b :: OpticKind)
(t :: OpticKind).
(s -> a) -> (b -> t) -> Iso s t a b
iso Text -> ByteString
StrictText.encodeUtf8 ByteString -> Text
StrictText.decodeUtf8
lazyTextUtf8 :: Iso' LazyText.Text LBS.ByteString
lazyTextUtf8 :: Iso' Text ByteString
lazyTextUtf8 = forall (s :: OpticKind) (a :: OpticKind) (b :: OpticKind)
(t :: OpticKind).
(s -> a) -> (b -> t) -> Iso s t a b
iso Text -> ByteString
LazyText.encodeUtf8 ByteString -> Text
LazyText.decodeUtf8
_JSON' :: (AsJSON t, FromJSON a, ToJSON a) => Prism' t a
_JSON' :: forall (t :: OpticKind) (a :: OpticKind).
(AsJSON t, FromJSON a, ToJSON a) =>
Prism' t a
_JSON' = forall (t :: OpticKind) (a :: OpticKind) (b :: OpticKind).
(AsJSON t, FromJSON a, ToJSON b) =>
Prism t t a b
_JSON
class IsKey t where
_Key :: Iso' t Key.Key
instance IsKey Key.Key where
_Key :: Iso' Key Key
_Key = forall (a :: OpticKind). Iso' a a
simple
{-# INLINE _Key #-}
instance IsKey String where
_Key :: Iso' String Key
_Key = forall (s :: OpticKind) (a :: OpticKind) (b :: OpticKind)
(t :: OpticKind).
(s -> a) -> (b -> t) -> Iso s t a b
iso String -> Key
Key.fromString Key -> String
Key.toString
{-# INLINE _Key #-}
instance IsKey Text where
_Key :: Iso' Text Key
_Key = forall (s :: OpticKind) (a :: OpticKind) (b :: OpticKind)
(t :: OpticKind).
(s -> a) -> (b -> t) -> Iso s t a b
iso Text -> Key
Key.fromText Key -> Text
Key.toText
{-# INLINE _Key #-}
instance IsKey LazyText.Text where
_Key :: Iso' Text Key
_Key = forall (s :: OpticKind) (a :: OpticKind) (b :: OpticKind)
(t :: OpticKind).
(s -> a) -> (b -> t) -> Iso s t a b
iso Text -> Text
LazyText.toStrict Text -> Text
LazyText.fromStrict forall (k :: OpticKind) (l :: OpticKind) (m :: OpticKind)
(is :: IxList) (js :: IxList) (ks :: IxList) (s :: OpticKind)
(t :: OpticKind) (u :: OpticKind) (v :: OpticKind) (a :: OpticKind)
(b :: OpticKind).
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% forall (t :: OpticKind). IsKey t => Iso' t Key
_Key
{-# INLINE _Key #-}
instance IsKey ShortText where
_Key :: Iso' ShortText Key
_Key = forall (s :: OpticKind) (a :: OpticKind) (b :: OpticKind)
(t :: OpticKind).
(s -> a) -> (b -> t) -> Iso s t a b
iso ShortText -> Key
Key.fromShortText Key -> ShortText
Key.toShortText
{-# INLINE _Key #-}
class AsJSON t where
_JSON :: (FromJSON a, ToJSON b) => Prism t t a b
instance AsJSON Strict.ByteString where
_JSON :: forall (a :: OpticKind) (b :: OpticKind).
(FromJSON a, ToJSON b) =>
Prism ByteString ByteString a b
_JSON = forall (s :: OpticKind) (a :: OpticKind) (b :: OpticKind)
(t :: OpticKind).
(s -> a) -> (b -> t) -> Iso s t a b
iso ByteString -> ByteString
LBS.fromStrict ByteString -> ByteString
LBS.toStrict forall (k :: OpticKind) (l :: OpticKind) (m :: OpticKind)
(is :: IxList) (js :: IxList) (ks :: IxList) (s :: OpticKind)
(t :: OpticKind) (u :: OpticKind) (v :: OpticKind) (a :: OpticKind)
(b :: OpticKind).
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% forall (t :: OpticKind) (a :: OpticKind) (b :: OpticKind).
(AsJSON t, FromJSON a, ToJSON b) =>
Prism t t a b
_JSON
{-# INLINE _JSON #-}
instance AsJSON LBS.ByteString where
_JSON :: forall (a :: OpticKind) (b :: OpticKind).
(FromJSON a, ToJSON b) =>
Prism ByteString ByteString a b
_JSON = forall (b :: OpticKind) (s :: OpticKind) (a :: OpticKind).
(b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' forall (a :: OpticKind). ToJSON a => a -> ByteString
encode forall (a :: OpticKind). FromJSON a => ByteString -> Maybe a
decode
{-# INLINE _JSON #-}
instance AsJSON String where
_JSON :: forall (a :: OpticKind) (b :: OpticKind).
(FromJSON a, ToJSON b) =>
Prism String String a b
_JSON = Iso' String ByteString
strictUtf8 forall (k :: OpticKind) (l :: OpticKind) (m :: OpticKind)
(is :: IxList) (js :: IxList) (ks :: IxList) (s :: OpticKind)
(t :: OpticKind) (u :: OpticKind) (v :: OpticKind) (a :: OpticKind)
(b :: OpticKind).
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% forall (t :: OpticKind) (a :: OpticKind) (b :: OpticKind).
(AsJSON t, FromJSON a, ToJSON b) =>
Prism t t a b
_JSON
{-# INLINE _JSON #-}
instance AsJSON Text where
_JSON :: forall (a :: OpticKind) (b :: OpticKind).
(FromJSON a, ToJSON b) =>
Prism Text Text a b
_JSON = Iso' Text ByteString
strictTextUtf8 forall (k :: OpticKind) (l :: OpticKind) (m :: OpticKind)
(is :: IxList) (js :: IxList) (ks :: IxList) (s :: OpticKind)
(t :: OpticKind) (u :: OpticKind) (v :: OpticKind) (a :: OpticKind)
(b :: OpticKind).
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% forall (t :: OpticKind) (a :: OpticKind) (b :: OpticKind).
(AsJSON t, FromJSON a, ToJSON b) =>
Prism t t a b
_JSON
{-# INLINE _JSON #-}
instance AsJSON LazyText.Text where
_JSON :: forall (a :: OpticKind) (b :: OpticKind).
(FromJSON a, ToJSON b) =>
Prism Text Text a b
_JSON = Iso' Text ByteString
lazyTextUtf8 forall (k :: OpticKind) (l :: OpticKind) (m :: OpticKind)
(is :: IxList) (js :: IxList) (ks :: IxList) (s :: OpticKind)
(t :: OpticKind) (u :: OpticKind) (v :: OpticKind) (a :: OpticKind)
(b :: OpticKind).
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% forall (t :: OpticKind) (a :: OpticKind) (b :: OpticKind).
(AsJSON t, FromJSON a, ToJSON b) =>
Prism t t a b
_JSON
{-# INLINE _JSON #-}
instance AsJSON Value where
_JSON :: forall (a :: OpticKind) (b :: OpticKind).
(FromJSON a, ToJSON b) =>
Prism Value Value a b
_JSON = forall (b :: OpticKind) (t :: OpticKind) (s :: OpticKind)
(a :: OpticKind).
(b -> t) -> (s -> Either t a) -> Prism s t a b
prism forall (a :: OpticKind). ToJSON a => a -> Value
toJSON forall (a :: OpticKind) b. (a -> b) -> a -> b
$ \Value
x -> case forall (a :: OpticKind). FromJSON a => Value -> Result a
fromJSON Value
x of
Success a
y -> forall (a :: OpticKind) (b :: OpticKind). b -> Either a b
Right a
y;
Result a
_ -> forall (a :: OpticKind) (b :: OpticKind). a -> Either a b
Left Value
x
{-# INLINE _JSON #-}
type instance Index Value = Key.Key
type instance IxValue Value = Value
instance Ixed Value where
ix :: Index Value -> Optic' (IxKind Value) NoIx Value (IxValue Value)
ix Index Value
i = forall (t :: OpticKind). AsValue t => Prism' t (KeyMap Value)
_Object forall (k :: OpticKind) (l :: OpticKind) (m :: OpticKind)
(is :: IxList) (js :: IxList) (ks :: IxList) (s :: OpticKind)
(t :: OpticKind) (u :: OpticKind) (v :: OpticKind) (a :: OpticKind)
(b :: OpticKind).
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% forall (m :: OpticKind).
Ixed m =>
Index m -> Optic' (IxKind m) NoIx m (IxValue m)
ix Index Value
i
{-# INLINE ix #-}
type instance Index (KM.KeyMap v) = Key.Key
type instance IxValue (KM.KeyMap v) = v
instance Ixed (KM.KeyMap v)
instance At (KM.KeyMap v) where
at :: Index (KeyMap v) -> Lens' (KeyMap v) (Maybe (IxValue (KeyMap v)))
at Index (KeyMap v)
i = forall (s :: OpticKind) (t :: OpticKind) (a :: OpticKind)
(b :: OpticKind).
LensVL s t a b -> Lens s t a b
lensVL (\Maybe v -> f (Maybe v)
f -> forall (f :: OpticKind -> OpticKind) (v :: OpticKind).
Functor f =>
(Maybe v -> f (Maybe v)) -> Key -> KeyMap v -> f (KeyMap v)
KM.alterF Maybe v -> f (Maybe v)
f Index (KeyMap v)
i)
{-# INLINE at #-}
instance Each Key.Key (KM.KeyMap a) (KM.KeyMap b) a b where
each :: IxTraversal Key (KeyMap a) (KeyMap b) a b
each = forall (i :: OpticKind) (s :: OpticKind) (t :: OpticKind)
(a :: OpticKind) (b :: OpticKind).
IxTraversalVL i s t a b -> IxTraversal i s t a b
itraversalVL forall (f :: OpticKind -> OpticKind) (v1 :: OpticKind)
(v2 :: OpticKind).
Applicative f =>
(Key -> v1 -> f v2) -> KeyMap v1 -> f (KeyMap v2)
KM.traverseWithKey
{-# INLINE[1] each #-}
pattern JSON :: (FromJSON a, ToJSON a, AsJSON t) => () => a -> t
pattern $bJSON :: forall (a :: OpticKind) (t :: OpticKind).
(FromJSON a, ToJSON a, AsJSON t) =>
a -> t
$mJSON :: forall {r} {a :: OpticKind} {t :: OpticKind}.
(FromJSON a, ToJSON a, AsJSON t) =>
t -> (a -> r) -> ((# #) -> r) -> r
JSON a <- (preview _JSON -> Just a) where
JSON a
a = forall (t :: OpticKind) (a :: OpticKind) (b :: OpticKind).
(AsJSON t, FromJSON a, ToJSON b) =>
Prism t t a b
_JSON forall (k :: OpticKind) (is :: IxList) (t :: OpticKind)
(b :: OpticKind).
Is k A_Review =>
Optic' k is t b -> b -> t
# a
a
pattern Value_ :: (FromJSON a, ToJSON a) => () => a -> Value
pattern $bValue_ :: forall (a :: OpticKind). (FromJSON a, ToJSON a) => a -> Value
$mValue_ :: forall {r} {a :: OpticKind}.
(FromJSON a, ToJSON a) =>
Value -> (a -> r) -> ((# #) -> r) -> r
Value_ a <- (fromJSON -> Success a) where
Value_ a
a = forall (a :: OpticKind). ToJSON a => a -> Value
toJSON a
a
pattern Number_ :: AsNumber t => Scientific -> t
pattern $bNumber_ :: forall (t :: OpticKind). AsNumber t => Scientific -> t
$mNumber_ :: forall {r} {t :: OpticKind}.
AsNumber t =>
t -> (Scientific -> r) -> ((# #) -> r) -> r
Number_ n <- (preview _Number -> Just n) where
Number_ Scientific
n = forall (t :: OpticKind). AsNumber t => Prism' t Scientific
_Number forall (k :: OpticKind) (is :: IxList) (t :: OpticKind)
(b :: OpticKind).
Is k A_Review =>
Optic' k is t b -> b -> t
# Scientific
n
pattern Double :: AsNumber t => Double -> t
pattern $bDouble :: forall (t :: OpticKind). AsNumber t => Double -> t
$mDouble :: forall {r} {t :: OpticKind}.
AsNumber t =>
t -> (Double -> r) -> ((# #) -> r) -> r
Double d <- (preview _Double -> Just d) where
Double Double
d = forall (t :: OpticKind). AsNumber t => Prism' t Double
_Double forall (k :: OpticKind) (is :: IxList) (t :: OpticKind)
(b :: OpticKind).
Is k A_Review =>
Optic' k is t b -> b -> t
# Double
d
pattern Integer :: AsNumber t => Integer -> t
pattern $bInteger :: forall (t :: OpticKind). AsNumber t => Integer -> t
$mInteger :: forall {r} {t :: OpticKind}.
AsNumber t =>
t -> (Integer -> r) -> ((# #) -> r) -> r
Integer i <- (preview _Integer -> Just i) where
Integer Integer
i = forall (t :: OpticKind). AsNumber t => Prism' t Integer
_Integer forall (k :: OpticKind) (is :: IxList) (t :: OpticKind)
(b :: OpticKind).
Is k A_Review =>
Optic' k is t b -> b -> t
# Integer
i
pattern Integral :: (AsNumber t, Integral a) => a -> t
pattern $bIntegral :: forall (t :: OpticKind) (a :: OpticKind).
(AsNumber t, Integral a) =>
a -> t
$mIntegral :: forall {r} {t :: OpticKind} {a :: OpticKind}.
(AsNumber t, Integral a) =>
t -> (a -> r) -> ((# #) -> r) -> r
Integral d <- (preview _Integral -> Just d) where
Integral a
d = forall (t :: OpticKind) (a :: OpticKind).
(AsNumber t, Integral a) =>
Prism' t a
_Integral forall (k :: OpticKind) (is :: IxList) (t :: OpticKind)
(b :: OpticKind).
Is k A_Review =>
Optic' k is t b -> b -> t
# a
d
pattern Bool_ :: AsValue t => Bool -> t
pattern $bBool_ :: forall (t :: OpticKind). AsValue t => Bool -> t
$mBool_ :: forall {r} {t :: OpticKind}.
AsValue t =>
t -> (Bool -> r) -> ((# #) -> r) -> r
Bool_ b <- (preview _Bool -> Just b) where
Bool_ Bool
b = forall (t :: OpticKind). AsValue t => Prism' t Bool
_Bool forall (k :: OpticKind) (is :: IxList) (t :: OpticKind)
(b :: OpticKind).
Is k A_Review =>
Optic' k is t b -> b -> t
# Bool
b
pattern String_ :: AsValue t => Text -> t
pattern $bString_ :: forall (t :: OpticKind). AsValue t => Text -> t
$mString_ :: forall {r} {t :: OpticKind}.
AsValue t =>
t -> (Text -> r) -> ((# #) -> r) -> r
String_ p <- (preview _String -> Just p) where
String_ Text
p = forall (t :: OpticKind). AsValue t => Prism' t Text
_String forall (k :: OpticKind) (is :: IxList) (t :: OpticKind)
(b :: OpticKind).
Is k A_Review =>
Optic' k is t b -> b -> t
# Text
p
pattern Null_ :: AsValue t => t
pattern $bNull_ :: forall (t :: OpticKind). AsValue t => t
$mNull_ :: forall {r} {t :: OpticKind}.
AsValue t =>
t -> ((# #) -> r) -> ((# #) -> r) -> r
Null_ <- (preview _Null -> Just ()) where
Null_ = forall (t :: OpticKind). AsValue t => Prism' t ()
_Null forall (k :: OpticKind) (is :: IxList) (t :: OpticKind)
(b :: OpticKind).
Is k A_Review =>
Optic' k is t b -> b -> t
# ()
pattern Key_ :: IsKey t => Key.Key -> t
pattern $bKey_ :: forall (t :: OpticKind). IsKey t => Key -> t
$mKey_ :: forall {r} {t :: OpticKind}.
IsKey t =>
t -> (Key -> r) -> ((# #) -> r) -> r
Key_ k <- (preview _Key -> Just k) where
Key_ Key
k = forall (t :: OpticKind). IsKey t => Iso' t Key
_Key forall (k :: OpticKind) (is :: IxList) (t :: OpticKind)
(b :: OpticKind).
Is k A_Review =>
Optic' k is t b -> b -> t
# Key
k