module ProjectM36.DataTypes.ByteString where import ProjectM36.Base import ProjectM36.AtomFunctionError import ProjectM36.AtomFunctionBody import qualified Data.HashSet as HS import qualified Data.ByteString.Base64 as B64 import qualified Data.Text.Encoding as TE bytestringAtomFunctions :: AtomFunctions bytestringAtomFunctions :: AtomFunctions bytestringAtomFunctions = [Function AtomFunctionBodyType] -> AtomFunctions forall a. (Eq a, Hashable a) => [a] -> HashSet a HS.fromList [ Function :: forall a. FunctionName -> [AtomType] -> FunctionBody a -> Function a Function { funcName :: FunctionName funcName = FunctionName "bytestring", funcType :: [AtomType] funcType = [AtomType TextAtomType, AtomType ByteStringAtomType], funcBody :: FunctionBody AtomFunctionBodyType funcBody = AtomFunctionBodyType -> FunctionBody AtomFunctionBodyType compiledAtomFunctionBody (AtomFunctionBodyType -> FunctionBody AtomFunctionBodyType) -> AtomFunctionBodyType -> FunctionBody AtomFunctionBodyType forall a b. (a -> b) -> a -> b $ \case TextAtom FunctionName textIn:[Atom] _ -> case ByteString -> Either String ByteString B64.decode (FunctionName -> ByteString TE.encodeUtf8 FunctionName textIn) of Left String err -> AtomFunctionError -> Either AtomFunctionError Atom forall a b. a -> Either a b Left (String -> AtomFunctionError AtomFunctionBytesDecodingError String err) Right ByteString bs -> Atom -> Either AtomFunctionError Atom forall (f :: * -> *) a. Applicative f => a -> f a pure (ByteString -> Atom ByteStringAtom ByteString bs) [Atom] _ -> AtomFunctionError -> Either AtomFunctionError Atom forall a b. a -> Either a b Left AtomFunctionError AtomFunctionTypeMismatchError } ]