module Serokell.Data.Variant.Class
( ToVariant (toVariant)
, FromVariant (fromVariant)
) where
import Universum
import Formatting (build, sformat, (%))
import Serokell.Data.Variant.Variant (Variant (..))
import Serokell.Util.Exceptions (throwText)
class ToVariant v where
toVariant :: v -> Variant
class FromVariant v where
fromVariant :: MonadThrow m => Variant -> m v
instance ToVariant Bool where
toVariant = VarBool
instance ToVariant Double where
toVariant = VarFloat
instance FromVariant Double where
fromVariant (VarFloat v) = pure v
fromVariant v = throwText $ sformat ("value is not Double: " % build) v