module Text.Digestive.Types
( Result (..)
, resultMapError
, Path
, toPath
, fromPath
, Method (..)
, FormInput (..)
, Env
) where
import Control.Applicative (Applicative (..))
import Data.Monoid (Monoid, mappend)
import Data.Text (Text)
import qualified Data.Text as T
data Result v a
= Success a
| Error v
deriving (Show)
instance Functor (Result v) where
fmap f (Success x) = Success (f x)
fmap _ (Error x) = Error x
instance Monoid v => Applicative (Result v) where
pure x = Success x
Error x <*> Error y = Error $ mappend x y
Error x <*> Success _ = Error x
Success _ <*> Error y = Error y
Success x <*> Success y = Success (x y)
instance Monad (Result v) where
return x = Success x
(Error x) >>= _ = Error x
(Success x) >>= f = f x
resultMapError :: (v -> w) -> Result v a -> Result w a
resultMapError f (Error x) = Error (f x)
resultMapError _ (Success x) = Success x
type Path = [Text]
toPath :: Text -> Path
toPath = filter (not . T.null) . T.split (== '.')
fromPath :: Path -> Text
fromPath = T.intercalate "."
data Method = Get | Post
deriving (Eq, Ord, Show)
data FormInput
= TextInput Text
| FileInput FilePath
deriving (Show)
type Env m = Path -> m [FormInput]