Last active
March 1, 2024 20:59
-
-
Save vrom911/118c73abff0e25369efc46e4d6c6f290 to your computer and use it in GitHub Desktop.
Kadena Interview
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Control.Monad | |
import Data.ByteString(ByteString) | |
import Control.Monad (ExceptT (..)) | |
import Data.Kind | |
type Errors = [String] | |
data HeistConfig (m :: Type -> Type) = HeistConfig | |
newtype TemplateName = TemplateName String | |
data HeistState (n :: Type -> Type) = HeistState | |
data MIMEType | |
initHeist :: Monad n => HeistConfig n -> n (Either Errors (HeistState n)) | |
initHeist = undefined | |
renderTemplate :: Monad n => HeistState n -> TemplateName -> Maybe (n Builder, MIMEType) | |
renderTemplate = undefined | |
toByteString :: Builder -> ByteString | |
toByteString = undefined | |
yourFunc1 :: HeistConfig IO -> TemplateName -> IO (Either Errors ByteString) | |
yourFunc1 hc nm = do | |
eitherState <- initHeist hc | |
case eitherState of | |
Left errs -> pure $ Left errs | |
Right heistState -> do | |
case renderTemplate heistState nm of | |
Nothing -> pure $ Left | |
Just (ioBuilder, _mt) -> Right . toByteString <$> ioBuilder | |
renderTemplateEither :: Monad n => HeistState n -> TemplateName -> Either Errors (n Builder, MIMETYpe) | |
renderTemplateEither hs tn = case renderTemplate hs tn of | |
Nothing -> Left ["Can not rennder template"] | |
Just x -> Right x | |
yourFunc2 :: HeistConfig IO -> TemplateName -> IO (Either Errors ByteString) | |
yourFunc2 hc nm = runExceptT $ do | |
hState <- ExceptT (initHeist hc) | |
(ioBuilder, _mt) <- ExceptT (pure $ renderTemplateEither state nm) | |
ExceptT (Right . toByteString <$> ioBuilder) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment