{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeFamilies #-}
module Data.Greskell.PMap
(
PMap
, lookup
, lookupM
, lookupAs
, lookupAs'
, lookupAsM
, lookupList
, lookupListAs
, lookupListAs'
, pMapInsert
, pMapDelete
, pMapLookup
, pMapToList
, pMapFromList
, Single
, Multi
, PMapKey (..)
, PMapLookupException (..)
, pMapDecribeError
, pMapToThrow
, pMapToFail
) where
import Prelude hiding (lookup)
import Control.Exception (Exception)
import Control.Monad.Catch (MonadCatch (..), MonadThrow (..))
import Control.Monad.Fail (MonadFail)
import Data.Aeson.Types (Parser)
import qualified Data.Foldable as F
import Data.Functor.Identity (Identity)
import Data.Greskell.AsIterator (AsIterator (..))
import Data.Greskell.GMap (GMapEntry)
import Data.Greskell.GraphSON (FromGraphSON (..), GValue, GraphSONTyped (..),
parseEither)
import qualified Data.HashMap.Strict as HM
import Data.Kind (Type)
import Data.List.NonEmpty (NonEmpty ((:|)))
import Data.Maybe (listToMaybe)
import Data.Monoid (Monoid (..))
import Data.Semigroup (Semigroup ((<>)))
import qualified Data.Semigroup as S
import Data.Text (Text, unpack)
import Data.Traversable (Traversable (traverse))
import Data.Greskell.NonEmptyLike (NonEmptyLike)
import qualified Data.Greskell.NonEmptyLike as NEL
newtype PMap c v
= PMap (HM.HashMap Text (c v))
deriving (PMap c v -> PMap c v -> Bool
(PMap c v -> PMap c v -> Bool)
-> (PMap c v -> PMap c v -> Bool) -> Eq (PMap c v)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall (c :: * -> *) v. Eq (c v) => PMap c v -> PMap c v -> Bool
$c== :: forall (c :: * -> *) v. Eq (c v) => PMap c v -> PMap c v -> Bool
== :: PMap c v -> PMap c v -> Bool
$c/= :: forall (c :: * -> *) v. Eq (c v) => PMap c v -> PMap c v -> Bool
/= :: PMap c v -> PMap c v -> Bool
Eq, (forall m. Monoid m => PMap c m -> m)
-> (forall m a. Monoid m => (a -> m) -> PMap c a -> m)
-> (forall m a. Monoid m => (a -> m) -> PMap c a -> m)
-> (forall a b. (a -> b -> b) -> b -> PMap c a -> b)
-> (forall a b. (a -> b -> b) -> b -> PMap c a -> b)
-> (forall b a. (b -> a -> b) -> b -> PMap c a -> b)
-> (forall b a. (b -> a -> b) -> b -> PMap c a -> b)
-> (forall a. (a -> a -> a) -> PMap c a -> a)
-> (forall a. (a -> a -> a) -> PMap c a -> a)
-> (forall a. PMap c a -> [a])
-> (forall a. PMap c a -> Bool)
-> (forall a. PMap c a -> Int)
-> (forall a. Eq a => a -> PMap c a -> Bool)
-> (forall a. Ord a => PMap c a -> a)
-> (forall a. Ord a => PMap c a -> a)
-> (forall a. Num a => PMap c a -> a)
-> (forall a. Num a => PMap c a -> a)
-> Foldable (PMap c)
forall a. Eq a => a -> PMap c a -> Bool
forall a. Num a => PMap c a -> a
forall a. Ord a => PMap c a -> a
forall m. Monoid m => PMap c m -> m
forall a. PMap c a -> Bool
forall a. PMap c a -> Int
forall a. PMap c a -> [a]
forall a. (a -> a -> a) -> PMap c a -> a
forall m a. Monoid m => (a -> m) -> PMap c a -> m
forall b a. (b -> a -> b) -> b -> PMap c a -> b
forall a b. (a -> b -> b) -> b -> PMap c a -> b
forall (c :: * -> *) a. (Foldable c, Eq a) => a -> PMap c a -> Bool
forall (c :: * -> *) a. (Foldable c, Num a) => PMap c a -> a
forall (c :: * -> *) a. (Foldable c, Ord a) => PMap c a -> a
forall (c :: * -> *) m. (Foldable c, Monoid m) => PMap c m -> m
forall (c :: * -> *) a. Foldable c => PMap c a -> Bool
forall (c :: * -> *) a. Foldable c => PMap c a -> Int
forall (c :: * -> *) a. Foldable c => PMap c a -> [a]
forall (c :: * -> *) a.
Foldable c =>
(a -> a -> a) -> PMap c a -> a
forall (c :: * -> *) m a.
(Foldable c, Monoid m) =>
(a -> m) -> PMap c a -> m
forall (c :: * -> *) b a.
Foldable c =>
(b -> a -> b) -> b -> PMap c a -> b
forall (c :: * -> *) a b.
Foldable c =>
(a -> b -> b) -> b -> PMap c a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
$cfold :: forall (c :: * -> *) m. (Foldable c, Monoid m) => PMap c m -> m
fold :: forall m. Monoid m => PMap c m -> m
$cfoldMap :: forall (c :: * -> *) m a.
(Foldable c, Monoid m) =>
(a -> m) -> PMap c a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> PMap c a -> m
$cfoldMap' :: forall (c :: * -> *) m a.
(Foldable c, Monoid m) =>
(a -> m) -> PMap c a -> m
foldMap' :: forall m a. Monoid m => (a -> m) -> PMap c a -> m
$cfoldr :: forall (c :: * -> *) a b.
Foldable c =>
(a -> b -> b) -> b -> PMap c a -> b
foldr :: forall a b. (a -> b -> b) -> b -> PMap c a -> b
$cfoldr' :: forall (c :: * -> *) a b.
Foldable c =>
(a -> b -> b) -> b -> PMap c a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> PMap c a -> b
$cfoldl :: forall (c :: * -> *) b a.
Foldable c =>
(b -> a -> b) -> b -> PMap c a -> b
foldl :: forall b a. (b -> a -> b) -> b -> PMap c a -> b
$cfoldl' :: forall (c :: * -> *) b a.
Foldable c =>
(b -> a -> b) -> b -> PMap c a -> b
foldl' :: forall b a. (b -> a -> b) -> b -> PMap c a -> b
$cfoldr1 :: forall (c :: * -> *) a.
Foldable c =>
(a -> a -> a) -> PMap c a -> a
foldr1 :: forall a. (a -> a -> a) -> PMap c a -> a
$cfoldl1 :: forall (c :: * -> *) a.
Foldable c =>
(a -> a -> a) -> PMap c a -> a
foldl1 :: forall a. (a -> a -> a) -> PMap c a -> a
$ctoList :: forall (c :: * -> *) a. Foldable c => PMap c a -> [a]
toList :: forall a. PMap c a -> [a]
$cnull :: forall (c :: * -> *) a. Foldable c => PMap c a -> Bool
null :: forall a. PMap c a -> Bool
$clength :: forall (c :: * -> *) a. Foldable c => PMap c a -> Int
length :: forall a. PMap c a -> Int
$celem :: forall (c :: * -> *) a. (Foldable c, Eq a) => a -> PMap c a -> Bool
elem :: forall a. Eq a => a -> PMap c a -> Bool
$cmaximum :: forall (c :: * -> *) a. (Foldable c, Ord a) => PMap c a -> a
maximum :: forall a. Ord a => PMap c a -> a
$cminimum :: forall (c :: * -> *) a. (Foldable c, Ord a) => PMap c a -> a
minimum :: forall a. Ord a => PMap c a -> a
$csum :: forall (c :: * -> *) a. (Foldable c, Num a) => PMap c a -> a
sum :: forall a. Num a => PMap c a -> a
$cproduct :: forall (c :: * -> *) a. (Foldable c, Num a) => PMap c a -> a
product :: forall a. Num a => PMap c a -> a
Foldable, (forall a b. (a -> b) -> PMap c a -> PMap c b)
-> (forall a b. a -> PMap c b -> PMap c a) -> Functor (PMap c)
forall a b. a -> PMap c b -> PMap c a
forall a b. (a -> b) -> PMap c a -> PMap c b
forall (c :: * -> *) a b. Functor c => a -> PMap c b -> PMap c a
forall (c :: * -> *) a b.
Functor c =>
(a -> b) -> PMap c a -> PMap c b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall (c :: * -> *) a b.
Functor c =>
(a -> b) -> PMap c a -> PMap c b
fmap :: forall a b. (a -> b) -> PMap c a -> PMap c b
$c<$ :: forall (c :: * -> *) a b. Functor c => a -> PMap c b -> PMap c a
<$ :: forall a b. a -> PMap c b -> PMap c a
Functor, Int -> PMap c v -> ShowS
[PMap c v] -> ShowS
PMap c v -> [Char]
(Int -> PMap c v -> ShowS)
-> (PMap c v -> [Char]) -> ([PMap c v] -> ShowS) -> Show (PMap c v)
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
forall (c :: * -> *) v. Show (c v) => Int -> PMap c v -> ShowS
forall (c :: * -> *) v. Show (c v) => [PMap c v] -> ShowS
forall (c :: * -> *) v. Show (c v) => PMap c v -> [Char]
$cshowsPrec :: forall (c :: * -> *) v. Show (c v) => Int -> PMap c v -> ShowS
showsPrec :: Int -> PMap c v -> ShowS
$cshow :: forall (c :: * -> *) v. Show (c v) => PMap c v -> [Char]
show :: PMap c v -> [Char]
$cshowList :: forall (c :: * -> *) v. Show (c v) => [PMap c v] -> ShowS
showList :: [PMap c v] -> ShowS
Show, Functor (PMap c)
Foldable (PMap c)
(Functor (PMap c), Foldable (PMap c)) =>
(forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> PMap c a -> f (PMap c b))
-> (forall (f :: * -> *) a.
Applicative f =>
PMap c (f a) -> f (PMap c a))
-> (forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> PMap c a -> m (PMap c b))
-> (forall (m :: * -> *) a.
Monad m =>
PMap c (m a) -> m (PMap c a))
-> Traversable (PMap c)
forall (t :: * -> *).
(Functor t, Foldable t) =>
(forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (c :: * -> *). Traversable c => Functor (PMap c)
forall (c :: * -> *). Traversable c => Foldable (PMap c)
forall (c :: * -> *) (m :: * -> *) a.
(Traversable c, Monad m) =>
PMap c (m a) -> m (PMap c a)
forall (c :: * -> *) (f :: * -> *) a.
(Traversable c, Applicative f) =>
PMap c (f a) -> f (PMap c a)
forall (c :: * -> *) (m :: * -> *) a b.
(Traversable c, Monad m) =>
(a -> m b) -> PMap c a -> m (PMap c b)
forall (c :: * -> *) (f :: * -> *) a b.
(Traversable c, Applicative f) =>
(a -> f b) -> PMap c a -> f (PMap c b)
forall (m :: * -> *) a. Monad m => PMap c (m a) -> m (PMap c a)
forall (f :: * -> *) a.
Applicative f =>
PMap c (f a) -> f (PMap c a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> PMap c a -> m (PMap c b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> PMap c a -> f (PMap c b)
$ctraverse :: forall (c :: * -> *) (f :: * -> *) a b.
(Traversable c, Applicative f) =>
(a -> f b) -> PMap c a -> f (PMap c b)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> PMap c a -> f (PMap c b)
$csequenceA :: forall (c :: * -> *) (f :: * -> *) a.
(Traversable c, Applicative f) =>
PMap c (f a) -> f (PMap c a)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
PMap c (f a) -> f (PMap c a)
$cmapM :: forall (c :: * -> *) (m :: * -> *) a b.
(Traversable c, Monad m) =>
(a -> m b) -> PMap c a -> m (PMap c b)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> PMap c a -> m (PMap c b)
$csequence :: forall (c :: * -> *) (m :: * -> *) a.
(Traversable c, Monad m) =>
PMap c (m a) -> m (PMap c a)
sequence :: forall (m :: * -> *) a. Monad m => PMap c (m a) -> m (PMap c a)
Traversable)
instance GraphSONTyped (PMap c v) where
gsonTypeFor :: PMap c v -> Text
gsonTypeFor PMap c v
_ = Text
"g:Map"
instance FromGraphSON (c v) => FromGraphSON (PMap c v) where
parseGraphSON :: GValue -> Parser (PMap c v)
parseGraphSON GValue
gv = (HashMap Text (c v) -> PMap c v)
-> Parser (HashMap Text (c v)) -> Parser (PMap c v)
forall a b. (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap HashMap Text (c v) -> PMap c v
forall (c :: * -> *) v. HashMap Text (c v) -> PMap c v
PMap (Parser (HashMap Text (c v)) -> Parser (PMap c v))
-> Parser (HashMap Text (c v)) -> Parser (PMap c v)
forall a b. (a -> b) -> a -> b
$ GValue -> Parser (HashMap Text (c v))
forall a. FromGraphSON a => GValue -> Parser a
parseGraphSON GValue
gv
instance NonEmptyLike c => Semigroup (PMap c v) where
(PMap HashMap Text (c v)
a) <> :: PMap c v -> PMap c v -> PMap c v
<> (PMap HashMap Text (c v)
b) = HashMap Text (c v) -> PMap c v
forall (c :: * -> *) v. HashMap Text (c v) -> PMap c v
PMap ((c v -> c v -> c v)
-> HashMap Text (c v) -> HashMap Text (c v) -> HashMap Text (c v)
forall k v.
Eq k =>
(v -> v -> v) -> HashMap k v -> HashMap k v -> HashMap k v
HM.unionWith c v -> c v -> c v
forall a. c a -> c a -> c a
forall (t :: * -> *) a. NonEmptyLike t => t a -> t a -> t a
NEL.append HashMap Text (c v)
a HashMap Text (c v)
b)
instance NonEmptyLike c => Monoid (PMap c v) where
mempty :: PMap c v
mempty = HashMap Text (c v) -> PMap c v
forall (c :: * -> *) v. HashMap Text (c v) -> PMap c v
PMap (HashMap Text (c v) -> PMap c v) -> HashMap Text (c v) -> PMap c v
forall a b. (a -> b) -> a -> b
$ HashMap Text (c v)
forall k v. HashMap k v
HM.empty
mappend :: PMap c v -> PMap c v -> PMap c v
mappend = PMap c v -> PMap c v -> PMap c v
forall a. Semigroup a => a -> a -> a
(<>)
instance AsIterator (PMap c v) where
type IteratorItem (PMap c v) = GMapEntry Text (c v)
pMapInsert :: NonEmptyLike c => Text -> v -> PMap c v -> PMap c v
pMapInsert :: forall (c :: * -> *) v.
NonEmptyLike c =>
Text -> v -> PMap c v -> PMap c v
pMapInsert Text
k v
v (PMap HashMap Text (c v)
hm) = HashMap Text (c v) -> PMap c v
forall (c :: * -> *) v. HashMap Text (c v) -> PMap c v
PMap (HashMap Text (c v) -> PMap c v) -> HashMap Text (c v) -> PMap c v
forall a b. (a -> b) -> a -> b
$ (c v -> c v -> c v)
-> Text -> c v -> HashMap Text (c v) -> HashMap Text (c v)
forall k v.
(Eq k, Hashable k) =>
(v -> v -> v) -> k -> v -> HashMap k v -> HashMap k v
HM.insertWith c v -> c v -> c v
forall a. c a -> c a -> c a
forall (t :: * -> *) a. NonEmptyLike t => t a -> t a -> t a
NEL.append Text
k (v -> c v
forall a. a -> c a
forall (t :: * -> *) a. NonEmptyLike t => a -> t a
NEL.singleton v
v) HashMap Text (c v)
hm
pMapDelete :: Text -> PMap c v -> PMap c v
pMapDelete :: forall (c :: * -> *) v. Text -> PMap c v -> PMap c v
pMapDelete Text
k (PMap HashMap Text (c v)
hm) = HashMap Text (c v) -> PMap c v
forall (c :: * -> *) v. HashMap Text (c v) -> PMap c v
PMap (HashMap Text (c v) -> PMap c v) -> HashMap Text (c v) -> PMap c v
forall a b. (a -> b) -> a -> b
$ Text -> HashMap Text (c v) -> HashMap Text (c v)
forall k v. (Eq k, Hashable k) => k -> HashMap k v -> HashMap k v
HM.delete Text
k HashMap Text (c v)
hm
pMapLookup :: NonEmptyLike c => Text -> PMap c v -> [v]
pMapLookup :: forall (c :: * -> *) v. NonEmptyLike c => Text -> PMap c v -> [v]
pMapLookup Text
k (PMap HashMap Text (c v)
hm) = [v] -> (c v -> [v]) -> Maybe (c v) -> [v]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (NonEmpty v -> [v]
forall a. NonEmpty a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
F.toList (NonEmpty v -> [v]) -> (c v -> NonEmpty v) -> c v -> [v]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. c v -> NonEmpty v
forall a. c a -> NonEmpty a
forall (t :: * -> *) a. NonEmptyLike t => t a -> NonEmpty a
NEL.toNonEmpty) (Maybe (c v) -> [v]) -> Maybe (c v) -> [v]
forall a b. (a -> b) -> a -> b
$ Text -> HashMap Text (c v) -> Maybe (c v)
forall k v. (Eq k, Hashable k) => k -> HashMap k v -> Maybe v
HM.lookup Text
k HashMap Text (c v)
hm
pMapToList :: F.Foldable c => PMap c v -> [(Text, v)]
pMapToList :: forall (c :: * -> *) v. Foldable c => PMap c v -> [(Text, v)]
pMapToList (PMap HashMap Text (c v)
hm) = (Text, c v) -> [(Text, v)]
forall {t :: * -> *} {a} {a}. Foldable t => (a, t a) -> [(a, a)]
expandValues ((Text, c v) -> [(Text, v)]) -> [(Text, c v)] -> [(Text, v)]
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< HashMap Text (c v) -> [(Text, c v)]
forall k v. HashMap k v -> [(k, v)]
HM.toList HashMap Text (c v)
hm
where
expandValues :: (a, t a) -> [(a, a)]
expandValues (a
k, t a
cv) = (a -> (a, a)) -> [a] -> [(a, a)]
forall a b. (a -> b) -> [a] -> [b]
map ((,) a
k) ([a] -> [(a, a)]) -> [a] -> [(a, a)]
forall a b. (a -> b) -> a -> b
$ t a -> [a]
forall a. t a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
F.toList t a
cv
pMapFromList :: NonEmptyLike c => [(Text, v)] -> PMap c v
pMapFromList :: forall (c :: * -> *) v. NonEmptyLike c => [(Text, v)] -> PMap c v
pMapFromList = ((Text, v) -> PMap c v -> PMap c v)
-> PMap c v -> [(Text, v)] -> PMap c v
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
F.foldr (Text, v) -> PMap c v -> PMap c v
forall {c :: * -> *} {v}.
NonEmptyLike c =>
(Text, v) -> PMap c v -> PMap c v
f PMap c v
forall a. Monoid a => a
mempty
where
f :: (Text, v) -> PMap c v -> PMap c v
f (Text
k, v
v) PMap c v
pm = Text -> v -> PMap c v -> PMap c v
forall (c :: * -> *) v.
NonEmptyLike c =>
Text -> v -> PMap c v -> PMap c v
pMapInsert Text
k v
v PMap c v
pm
lookup :: (PMapKey k, NonEmptyLike c) => k -> PMap c v -> Maybe v
lookup :: forall k (c :: * -> *) v.
(PMapKey k, NonEmptyLike c) =>
k -> PMap c v -> Maybe v
lookup k
k PMap c v
pm = [v] -> Maybe v
forall a. [a] -> Maybe a
listToMaybe ([v] -> Maybe v) -> [v] -> Maybe v
forall a b. (a -> b) -> a -> b
$ k -> PMap c v -> [v]
forall k (c :: * -> *) v.
(PMapKey k, NonEmptyLike c) =>
k -> PMap c v -> [v]
lookupList k
k PMap c v
pm
lookupM :: (PMapKey k, NonEmptyLike c, MonadThrow m) => k -> PMap c v -> m v
lookupM :: forall k (c :: * -> *) (m :: * -> *) v.
(PMapKey k, NonEmptyLike c, MonadThrow m) =>
k -> PMap c v -> m v
lookupM k
k PMap c v
pm = m v -> (v -> m v) -> Maybe v -> m v
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (PMapLookupException -> m v
forall e a. (HasCallStack, Exception e) => e -> m a
forall (m :: * -> *) e a.
(MonadThrow m, HasCallStack, Exception e) =>
e -> m a
throwM (PMapLookupException -> m v) -> PMapLookupException -> m v
forall a b. (a -> b) -> a -> b
$ Text -> PMapLookupException
PMapNoSuchKey (Text -> PMapLookupException) -> Text -> PMapLookupException
forall a b. (a -> b) -> a -> b
$ k -> Text
forall k. PMapKey k => k -> Text
keyText k
k) v -> m v
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe v -> m v) -> Maybe v -> m v
forall a b. (a -> b) -> a -> b
$ k -> PMap c v -> Maybe v
forall k (c :: * -> *) v.
(PMapKey k, NonEmptyLike c) =>
k -> PMap c v -> Maybe v
lookup k
k PMap c v
pm
lookupAs :: (PMapKey k, NonEmptyLike c, PMapValue k ~ a, FromGraphSON a)
=> k -> PMap c GValue -> Either PMapLookupException a
lookupAs :: forall k (c :: * -> *) a.
(PMapKey k, NonEmptyLike c, PMapValue k ~ a, FromGraphSON a) =>
k -> PMap c GValue -> Either PMapLookupException a
lookupAs k
k PMap c GValue
pm =
case k -> PMap c GValue -> Maybe GValue
forall k (c :: * -> *) v.
(PMapKey k, NonEmptyLike c) =>
k -> PMap c v -> Maybe v
lookup k
k PMap c GValue
pm of
Maybe GValue
Nothing -> PMapLookupException -> Either PMapLookupException a
forall a b. a -> Either a b
Left (PMapLookupException -> Either PMapLookupException a)
-> PMapLookupException -> Either PMapLookupException a
forall a b. (a -> b) -> a -> b
$ Text -> PMapLookupException
PMapNoSuchKey Text
kt
Just GValue
gv -> ([Char] -> Either PMapLookupException a)
-> (a -> Either PMapLookupException a)
-> Either [Char] a
-> Either PMapLookupException a
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (PMapLookupException -> Either PMapLookupException a
forall a b. a -> Either a b
Left (PMapLookupException -> Either PMapLookupException a)
-> ([Char] -> PMapLookupException)
-> [Char]
-> Either PMapLookupException a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> [Char] -> PMapLookupException
PMapParseError Text
kt) a -> Either PMapLookupException a
forall a b. b -> Either a b
Right (Either [Char] a -> Either PMapLookupException a)
-> Either [Char] a -> Either PMapLookupException a
forall a b. (a -> b) -> a -> b
$ GValue -> Either [Char] a
forall a. FromGraphSON a => GValue -> Either [Char] a
parseEither GValue
gv
where
kt :: Text
kt = k -> Text
forall k. PMapKey k => k -> Text
keyText k
k
lookupAs' :: (PMapKey k, NonEmptyLike c, PMapValue k ~ (Maybe a), FromGraphSON a)
=> k -> PMap c GValue -> Either PMapLookupException (Maybe a)
lookupAs' :: forall k (c :: * -> *) a.
(PMapKey k, NonEmptyLike c, PMapValue k ~ Maybe a,
FromGraphSON a) =>
k -> PMap c GValue -> Either PMapLookupException (Maybe a)
lookupAs' k
k PMap c GValue
pm = (PMapLookupException -> Either PMapLookupException (Maybe a))
-> (Maybe a -> Either PMapLookupException (Maybe a))
-> Either PMapLookupException (Maybe a)
-> Either PMapLookupException (Maybe a)
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either PMapLookupException -> Either PMapLookupException (Maybe a)
forall {a}.
PMapLookupException -> Either PMapLookupException (Maybe a)
fromError Maybe a -> Either PMapLookupException (Maybe a)
forall a b. b -> Either a b
Right (Either PMapLookupException (Maybe a)
-> Either PMapLookupException (Maybe a))
-> Either PMapLookupException (Maybe a)
-> Either PMapLookupException (Maybe a)
forall a b. (a -> b) -> a -> b
$ k -> PMap c GValue -> Either PMapLookupException (Maybe a)
forall k (c :: * -> *) a.
(PMapKey k, NonEmptyLike c, PMapValue k ~ a, FromGraphSON a) =>
k -> PMap c GValue -> Either PMapLookupException a
lookupAs k
k PMap c GValue
pm
where
fromError :: PMapLookupException -> Either PMapLookupException (Maybe a)
fromError (PMapNoSuchKey Text
_) = Maybe a -> Either PMapLookupException (Maybe a)
forall a b. b -> Either a b
Right Maybe a
forall a. Maybe a
Nothing
fromError PMapLookupException
e = PMapLookupException -> Either PMapLookupException (Maybe a)
forall a b. a -> Either a b
Left PMapLookupException
e
lookupAsM :: (PMapKey k, NonEmptyLike c, PMapValue k ~ a, FromGraphSON a, MonadThrow m)
=> k -> PMap c GValue -> m a
lookupAsM :: forall k (c :: * -> *) a (m :: * -> *).
(PMapKey k, NonEmptyLike c, PMapValue k ~ a, FromGraphSON a,
MonadThrow m) =>
k -> PMap c GValue -> m a
lookupAsM k
k PMap c GValue
pm = Either PMapLookupException a -> m a
forall (m :: * -> *) a.
MonadThrow m =>
Either PMapLookupException a -> m a
pMapToThrow (Either PMapLookupException a -> m a)
-> Either PMapLookupException a -> m a
forall a b. (a -> b) -> a -> b
$ k -> PMap c GValue -> Either PMapLookupException a
forall k (c :: * -> *) a.
(PMapKey k, NonEmptyLike c, PMapValue k ~ a, FromGraphSON a) =>
k -> PMap c GValue -> Either PMapLookupException a
lookupAs k
k PMap c GValue
pm
lookupList :: (PMapKey k, NonEmptyLike c) => k -> PMap c v -> [v]
lookupList :: forall k (c :: * -> *) v.
(PMapKey k, NonEmptyLike c) =>
k -> PMap c v -> [v]
lookupList k
k PMap c v
pm = Text -> PMap c v -> [v]
forall (c :: * -> *) v. NonEmptyLike c => Text -> PMap c v -> [v]
pMapLookup (k -> Text
forall k. PMapKey k => k -> Text
keyText k
k) PMap c v
pm
lookupListAs :: (PMapKey k, NonEmptyLike c, PMapValue k ~ a, FromGraphSON a)
=> k -> PMap c GValue -> Either PMapLookupException (NonEmpty a)
lookupListAs :: forall k (c :: * -> *) a.
(PMapKey k, NonEmptyLike c, PMapValue k ~ a, FromGraphSON a) =>
k -> PMap c GValue -> Either PMapLookupException (NonEmpty a)
lookupListAs k
k PMap c GValue
pm =
case k -> PMap c GValue -> [GValue]
forall k (c :: * -> *) v.
(PMapKey k, NonEmptyLike c) =>
k -> PMap c v -> [v]
lookupList k
k PMap c GValue
pm of
[] -> PMapLookupException -> Either PMapLookupException (NonEmpty a)
forall a b. a -> Either a b
Left (PMapLookupException -> Either PMapLookupException (NonEmpty a))
-> PMapLookupException -> Either PMapLookupException (NonEmpty a)
forall a b. (a -> b) -> a -> b
$ Text -> PMapLookupException
PMapNoSuchKey Text
kt
(GValue
x : [GValue]
rest) -> ([Char] -> Either PMapLookupException (NonEmpty a))
-> (NonEmpty a -> Either PMapLookupException (NonEmpty a))
-> Either [Char] (NonEmpty a)
-> Either PMapLookupException (NonEmpty a)
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (PMapLookupException -> Either PMapLookupException (NonEmpty a)
forall a b. a -> Either a b
Left (PMapLookupException -> Either PMapLookupException (NonEmpty a))
-> ([Char] -> PMapLookupException)
-> [Char]
-> Either PMapLookupException (NonEmpty a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> [Char] -> PMapLookupException
PMapParseError Text
kt) NonEmpty a -> Either PMapLookupException (NonEmpty a)
forall a b. b -> Either a b
Right (Either [Char] (NonEmpty a)
-> Either PMapLookupException (NonEmpty a))
-> Either [Char] (NonEmpty a)
-> Either PMapLookupException (NonEmpty a)
forall a b. (a -> b) -> a -> b
$ (GValue -> Either [Char] a)
-> NonEmpty GValue -> Either [Char] (NonEmpty a)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> NonEmpty a -> f (NonEmpty b)
traverse GValue -> Either [Char] a
forall a. FromGraphSON a => GValue -> Either [Char] a
parseEither (GValue
x GValue -> [GValue] -> NonEmpty GValue
forall a. a -> [a] -> NonEmpty a
:| [GValue]
rest)
where
kt :: Text
kt = k -> Text
forall k. PMapKey k => k -> Text
keyText k
k
lookupListAs' :: (PMapKey k, NonEmptyLike c, PMapValue k ~ (Maybe a), FromGraphSON a)
=> k -> PMap c GValue -> Either PMapLookupException [Maybe a]
lookupListAs' :: forall k (c :: * -> *) a.
(PMapKey k, NonEmptyLike c, PMapValue k ~ Maybe a,
FromGraphSON a) =>
k -> PMap c GValue -> Either PMapLookupException [Maybe a]
lookupListAs' k
k PMap c GValue
pm = (PMapLookupException -> Either PMapLookupException [Maybe a])
-> (NonEmpty (Maybe a) -> Either PMapLookupException [Maybe a])
-> Either PMapLookupException (NonEmpty (Maybe a))
-> Either PMapLookupException [Maybe a]
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either PMapLookupException -> Either PMapLookupException [Maybe a]
forall {a}. PMapLookupException -> Either PMapLookupException [a]
fromError ([Maybe a] -> Either PMapLookupException [Maybe a]
forall a b. b -> Either a b
Right ([Maybe a] -> Either PMapLookupException [Maybe a])
-> (NonEmpty (Maybe a) -> [Maybe a])
-> NonEmpty (Maybe a)
-> Either PMapLookupException [Maybe a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NonEmpty (Maybe a) -> [Maybe a]
forall a. NonEmpty a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
F.toList) (Either PMapLookupException (NonEmpty (Maybe a))
-> Either PMapLookupException [Maybe a])
-> Either PMapLookupException (NonEmpty (Maybe a))
-> Either PMapLookupException [Maybe a]
forall a b. (a -> b) -> a -> b
$ k
-> PMap c GValue -> Either PMapLookupException (NonEmpty (Maybe a))
forall k (c :: * -> *) a.
(PMapKey k, NonEmptyLike c, PMapValue k ~ a, FromGraphSON a) =>
k -> PMap c GValue -> Either PMapLookupException (NonEmpty a)
lookupListAs k
k PMap c GValue
pm
where
fromError :: PMapLookupException -> Either PMapLookupException [a]
fromError (PMapNoSuchKey Text
_) = [a] -> Either PMapLookupException [a]
forall a b. b -> Either a b
Right []
fromError PMapLookupException
e = PMapLookupException -> Either PMapLookupException [a]
forall a b. a -> Either a b
Left PMapLookupException
e
type Single = S.First
newtype Multi a
= Multi (NonEmpty a)
deriving (Multi a -> Multi a -> Bool
(Multi a -> Multi a -> Bool)
-> (Multi a -> Multi a -> Bool) -> Eq (Multi a)
forall a. Eq a => Multi a -> Multi a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall a. Eq a => Multi a -> Multi a -> Bool
== :: Multi a -> Multi a -> Bool
$c/= :: forall a. Eq a => Multi a -> Multi a -> Bool
/= :: Multi a -> Multi a -> Bool
Eq, (forall m. Monoid m => Multi m -> m)
-> (forall m a. Monoid m => (a -> m) -> Multi a -> m)
-> (forall m a. Monoid m => (a -> m) -> Multi a -> m)
-> (forall a b. (a -> b -> b) -> b -> Multi a -> b)
-> (forall a b. (a -> b -> b) -> b -> Multi a -> b)
-> (forall b a. (b -> a -> b) -> b -> Multi a -> b)
-> (forall b a. (b -> a -> b) -> b -> Multi a -> b)
-> (forall a. (a -> a -> a) -> Multi a -> a)
-> (forall a. (a -> a -> a) -> Multi a -> a)
-> (forall a. Multi a -> [a])
-> (forall a. Multi a -> Bool)
-> (forall a. Multi a -> Int)
-> (forall a. Eq a => a -> Multi a -> Bool)
-> (forall a. Ord a => Multi a -> a)
-> (forall a. Ord a => Multi a -> a)
-> (forall a. Num a => Multi a -> a)
-> (forall a. Num a => Multi a -> a)
-> Foldable Multi
forall a. Eq a => a -> Multi a -> Bool
forall a. Num a => Multi a -> a
forall a. Ord a => Multi a -> a
forall m. Monoid m => Multi m -> m
forall a. Multi a -> Bool
forall a. Multi a -> Int
forall a. Multi a -> [a]
forall a. (a -> a -> a) -> Multi a -> a
forall m a. Monoid m => (a -> m) -> Multi a -> m
forall b a. (b -> a -> b) -> b -> Multi a -> b
forall a b. (a -> b -> b) -> b -> Multi a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
$cfold :: forall m. Monoid m => Multi m -> m
fold :: forall m. Monoid m => Multi m -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> Multi a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> Multi a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> Multi a -> m
foldMap' :: forall m a. Monoid m => (a -> m) -> Multi a -> m
$cfoldr :: forall a b. (a -> b -> b) -> b -> Multi a -> b
foldr :: forall a b. (a -> b -> b) -> b -> Multi a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> Multi a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> Multi a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> Multi a -> b
foldl :: forall b a. (b -> a -> b) -> b -> Multi a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> Multi a -> b
foldl' :: forall b a. (b -> a -> b) -> b -> Multi a -> b
$cfoldr1 :: forall a. (a -> a -> a) -> Multi a -> a
foldr1 :: forall a. (a -> a -> a) -> Multi a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> Multi a -> a
foldl1 :: forall a. (a -> a -> a) -> Multi a -> a
$ctoList :: forall a. Multi a -> [a]
toList :: forall a. Multi a -> [a]
$cnull :: forall a. Multi a -> Bool
null :: forall a. Multi a -> Bool
$clength :: forall a. Multi a -> Int
length :: forall a. Multi a -> Int
$celem :: forall a. Eq a => a -> Multi a -> Bool
elem :: forall a. Eq a => a -> Multi a -> Bool
$cmaximum :: forall a. Ord a => Multi a -> a
maximum :: forall a. Ord a => Multi a -> a
$cminimum :: forall a. Ord a => Multi a -> a
minimum :: forall a. Ord a => Multi a -> a
$csum :: forall a. Num a => Multi a -> a
sum :: forall a. Num a => Multi a -> a
$cproduct :: forall a. Num a => Multi a -> a
product :: forall a. Num a => Multi a -> a
Foldable, GValue -> Parser (Multi a)
(GValue -> Parser (Multi a)) -> FromGraphSON (Multi a)
forall a. FromGraphSON a => GValue -> Parser (Multi a)
forall a. (GValue -> Parser a) -> FromGraphSON a
$cparseGraphSON :: forall a. FromGraphSON a => GValue -> Parser (Multi a)
parseGraphSON :: GValue -> Parser (Multi a)
FromGraphSON, (forall a b. (a -> b) -> Multi a -> Multi b)
-> (forall a b. a -> Multi b -> Multi a) -> Functor Multi
forall a b. a -> Multi b -> Multi a
forall a b. (a -> b) -> Multi a -> Multi b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a b. (a -> b) -> Multi a -> Multi b
fmap :: forall a b. (a -> b) -> Multi a -> Multi b
$c<$ :: forall a b. a -> Multi b -> Multi a
<$ :: forall a b. a -> Multi b -> Multi a
Functor, Foldable Multi
Foldable Multi =>
(forall a. a -> Multi a)
-> (forall a. Multi a -> Multi a -> Multi a)
-> (forall a. Multi a -> NonEmpty a)
-> NonEmptyLike Multi
forall a. a -> Multi a
forall a. Multi a -> NonEmpty a
forall a. Multi a -> Multi a -> Multi a
forall (t :: * -> *).
Foldable t =>
(forall a. a -> t a)
-> (forall a. t a -> t a -> t a)
-> (forall a. t a -> NonEmpty a)
-> NonEmptyLike t
$csingleton :: forall a. a -> Multi a
singleton :: forall a. a -> Multi a
$cappend :: forall a. Multi a -> Multi a -> Multi a
append :: forall a. Multi a -> Multi a -> Multi a
$ctoNonEmpty :: forall a. Multi a -> NonEmpty a
toNonEmpty :: forall a. Multi a -> NonEmpty a
NonEmptyLike, Eq (Multi a)
Eq (Multi a) =>
(Multi a -> Multi a -> Ordering)
-> (Multi a -> Multi a -> Bool)
-> (Multi a -> Multi a -> Bool)
-> (Multi a -> Multi a -> Bool)
-> (Multi a -> Multi a -> Bool)
-> (Multi a -> Multi a -> Multi a)
-> (Multi a -> Multi a -> Multi a)
-> Ord (Multi a)
Multi a -> Multi a -> Bool
Multi a -> Multi a -> Ordering
Multi a -> Multi a -> Multi a
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall a. Ord a => Eq (Multi a)
forall a. Ord a => Multi a -> Multi a -> Bool
forall a. Ord a => Multi a -> Multi a -> Ordering
forall a. Ord a => Multi a -> Multi a -> Multi a
$ccompare :: forall a. Ord a => Multi a -> Multi a -> Ordering
compare :: Multi a -> Multi a -> Ordering
$c< :: forall a. Ord a => Multi a -> Multi a -> Bool
< :: Multi a -> Multi a -> Bool
$c<= :: forall a. Ord a => Multi a -> Multi a -> Bool
<= :: Multi a -> Multi a -> Bool
$c> :: forall a. Ord a => Multi a -> Multi a -> Bool
> :: Multi a -> Multi a -> Bool
$c>= :: forall a. Ord a => Multi a -> Multi a -> Bool
>= :: Multi a -> Multi a -> Bool
$cmax :: forall a. Ord a => Multi a -> Multi a -> Multi a
max :: Multi a -> Multi a -> Multi a
$cmin :: forall a. Ord a => Multi a -> Multi a -> Multi a
min :: Multi a -> Multi a -> Multi a
Ord, NonEmpty (Multi a) -> Multi a
Multi a -> Multi a -> Multi a
(Multi a -> Multi a -> Multi a)
-> (NonEmpty (Multi a) -> Multi a)
-> (forall b. Integral b => b -> Multi a -> Multi a)
-> Semigroup (Multi a)
forall b. Integral b => b -> Multi a -> Multi a
forall a. NonEmpty (Multi a) -> Multi a
forall a. Multi a -> Multi a -> Multi a
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
forall a b. Integral b => b -> Multi a -> Multi a
$c<> :: forall a. Multi a -> Multi a -> Multi a
<> :: Multi a -> Multi a -> Multi a
$csconcat :: forall a. NonEmpty (Multi a) -> Multi a
sconcat :: NonEmpty (Multi a) -> Multi a
$cstimes :: forall a b. Integral b => b -> Multi a -> Multi a
stimes :: forall b. Integral b => b -> Multi a -> Multi a
Semigroup, Int -> Multi a -> ShowS
[Multi a] -> ShowS
Multi a -> [Char]
(Int -> Multi a -> ShowS)
-> (Multi a -> [Char]) -> ([Multi a] -> ShowS) -> Show (Multi a)
forall a. Show a => Int -> Multi a -> ShowS
forall a. Show a => [Multi a] -> ShowS
forall a. Show a => Multi a -> [Char]
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> Multi a -> ShowS
showsPrec :: Int -> Multi a -> ShowS
$cshow :: forall a. Show a => Multi a -> [Char]
show :: Multi a -> [Char]
$cshowList :: forall a. Show a => [Multi a] -> ShowS
showList :: [Multi a] -> ShowS
Show, Functor Multi
Foldable Multi
(Functor Multi, Foldable Multi) =>
(forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Multi a -> f (Multi b))
-> (forall (f :: * -> *) a.
Applicative f =>
Multi (f a) -> f (Multi a))
-> (forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Multi a -> m (Multi b))
-> (forall (m :: * -> *) a. Monad m => Multi (m a) -> m (Multi a))
-> Traversable Multi
forall (t :: * -> *).
(Functor t, Foldable t) =>
(forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a. Monad m => Multi (m a) -> m (Multi a)
forall (f :: * -> *) a. Applicative f => Multi (f a) -> f (Multi a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Multi a -> m (Multi b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Multi a -> f (Multi b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Multi a -> f (Multi b)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Multi a -> f (Multi b)
$csequenceA :: forall (f :: * -> *) a. Applicative f => Multi (f a) -> f (Multi a)
sequenceA :: forall (f :: * -> *) a. Applicative f => Multi (f a) -> f (Multi a)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Multi a -> m (Multi b)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Multi a -> m (Multi b)
$csequence :: forall (m :: * -> *) a. Monad m => Multi (m a) -> m (Multi a)
sequence :: forall (m :: * -> *) a. Monad m => Multi (m a) -> m (Multi a)
Traversable)
class PMapKey k where
type PMapValue k :: Type
keyText :: k -> Text
instance PMapKey Text where
type PMapValue Text = GValue
keyText :: Text -> Text
keyText = Text -> Text
forall a. a -> a
id
data PMapLookupException
= PMapNoSuchKey Text
| PMapParseError Text String
deriving (PMapLookupException -> PMapLookupException -> Bool
(PMapLookupException -> PMapLookupException -> Bool)
-> (PMapLookupException -> PMapLookupException -> Bool)
-> Eq PMapLookupException
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PMapLookupException -> PMapLookupException -> Bool
== :: PMapLookupException -> PMapLookupException -> Bool
$c/= :: PMapLookupException -> PMapLookupException -> Bool
/= :: PMapLookupException -> PMapLookupException -> Bool
Eq, Eq PMapLookupException
Eq PMapLookupException =>
(PMapLookupException -> PMapLookupException -> Ordering)
-> (PMapLookupException -> PMapLookupException -> Bool)
-> (PMapLookupException -> PMapLookupException -> Bool)
-> (PMapLookupException -> PMapLookupException -> Bool)
-> (PMapLookupException -> PMapLookupException -> Bool)
-> (PMapLookupException
-> PMapLookupException -> PMapLookupException)
-> (PMapLookupException
-> PMapLookupException -> PMapLookupException)
-> Ord PMapLookupException
PMapLookupException -> PMapLookupException -> Bool
PMapLookupException -> PMapLookupException -> Ordering
PMapLookupException -> PMapLookupException -> PMapLookupException
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: PMapLookupException -> PMapLookupException -> Ordering
compare :: PMapLookupException -> PMapLookupException -> Ordering
$c< :: PMapLookupException -> PMapLookupException -> Bool
< :: PMapLookupException -> PMapLookupException -> Bool
$c<= :: PMapLookupException -> PMapLookupException -> Bool
<= :: PMapLookupException -> PMapLookupException -> Bool
$c> :: PMapLookupException -> PMapLookupException -> Bool
> :: PMapLookupException -> PMapLookupException -> Bool
$c>= :: PMapLookupException -> PMapLookupException -> Bool
>= :: PMapLookupException -> PMapLookupException -> Bool
$cmax :: PMapLookupException -> PMapLookupException -> PMapLookupException
max :: PMapLookupException -> PMapLookupException -> PMapLookupException
$cmin :: PMapLookupException -> PMapLookupException -> PMapLookupException
min :: PMapLookupException -> PMapLookupException -> PMapLookupException
Ord, Int -> PMapLookupException -> ShowS
[PMapLookupException] -> ShowS
PMapLookupException -> [Char]
(Int -> PMapLookupException -> ShowS)
-> (PMapLookupException -> [Char])
-> ([PMapLookupException] -> ShowS)
-> Show PMapLookupException
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PMapLookupException -> ShowS
showsPrec :: Int -> PMapLookupException -> ShowS
$cshow :: PMapLookupException -> [Char]
show :: PMapLookupException -> [Char]
$cshowList :: [PMapLookupException] -> ShowS
showList :: [PMapLookupException] -> ShowS
Show)
instance Exception PMapLookupException
pMapDecribeError :: PMapLookupException -> String
pMapDecribeError :: PMapLookupException -> [Char]
pMapDecribeError (PMapNoSuchKey Text
k) = [Char]
"Property '" [Char] -> ShowS
forall a. [a] -> [a] -> [a]
++ Text -> [Char]
unpack Text
k [Char] -> ShowS
forall a. [a] -> [a] -> [a]
++ [Char]
"' does not exist."
pMapDecribeError (PMapParseError Text
k [Char]
pe) = [Char]
"Parse error of property '" [Char] -> ShowS
forall a. [a] -> [a] -> [a]
++ Text -> [Char]
unpack Text
k [Char] -> ShowS
forall a. [a] -> [a] -> [a]
++ [Char]
"': " [Char] -> ShowS
forall a. [a] -> [a] -> [a]
++ [Char]
pe
pMapToThrow :: MonadThrow m => Either PMapLookupException a -> m a
pMapToThrow :: forall (m :: * -> *) a.
MonadThrow m =>
Either PMapLookupException a -> m a
pMapToThrow (Left PMapLookupException
e) = PMapLookupException -> m a
forall e a. (HasCallStack, Exception e) => e -> m a
forall (m :: * -> *) e a.
(MonadThrow m, HasCallStack, Exception e) =>
e -> m a
throwM PMapLookupException
e
pMapToThrow (Right a
a) = a -> m a
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return a
a
pMapToFail :: MonadFail m => Either PMapLookupException a -> m a
pMapToFail :: forall (m :: * -> *) a.
MonadFail m =>
Either PMapLookupException a -> m a
pMapToFail (Left PMapLookupException
e) = [Char] -> m a
forall a. [Char] -> m a
forall (m :: * -> *) a. MonadFail m => [Char] -> m a
fail ([Char] -> m a) -> [Char] -> m a
forall a b. (a -> b) -> a -> b
$ PMapLookupException -> [Char]
pMapDecribeError PMapLookupException
e
pMapToFail (Right a
a) = a -> m a
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return a
a