{-# LANGUAGE TypeFamilies, GeneralizedNewtypeDeriving #-}
module Data.Greskell.AsLabel
(
AsLabel(..),
SelectedMap,
unsafeCastAsLabel,
lookup,
lookupM,
lookupAs,
lookupAsM,
PMapLookupException(..)
) where
import Prelude hiding (lookup)
import Control.Exception (Exception)
import Control.Monad.Catch (MonadThrow(..))
import Data.Foldable (Foldable)
import Data.Hashable (Hashable)
import Data.HashMap.Strict (HashMap)
import qualified Data.HashMap.Strict as HM
import Data.Greskell.GraphSON (GValue, GraphSONTyped(..), FromGraphSON(..), parseEither)
import Data.Greskell.Greskell (ToGreskell(..))
import qualified Data.Greskell.Greskell as Greskell
import Data.String (IsString(..))
import Data.Text (Text)
import Data.Traversable (Traversable)
import Data.Greskell.PMap
( PMap, PMapKey(..), Single,
lookup, lookupM, lookupAs, lookupAsM, PMapLookupException(..)
)
newtype AsLabel a = AsLabel { unAsLabel :: Text }
deriving (Show,Eq,Ord,Hashable)
instance IsString (AsLabel a) where
fromString = AsLabel . fromString
instance ToGreskell (AsLabel a) where
type GreskellReturn (AsLabel a) = Text
toGreskell (AsLabel t) = Greskell.string t
instance Functor AsLabel where
fmap _ (AsLabel t) = AsLabel t
instance PMapKey (AsLabel a) where
type PMapValue (AsLabel a) = a
keyText = unAsLabel
type SelectedMap = PMap Single
unsafeCastAsLabel :: AsLabel a -> AsLabel b
unsafeCastAsLabel = AsLabel . unAsLabel