Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add instances #35

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/Servant/Multipart.hs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ data MultipartData tag = MultipartData
, files :: [FileData tag]
}

instance Semigroup (MultipartData tag) where
d1 <> d2 = MultipartData (inputs d1 <> inputs d2) (files d1 <> files d2)

instance Monoid (MultipartData tag) where
mempty = MultipartData [] []

fromRaw :: forall tag. ([Network.Wai.Parse.Param], [File (MultipartResult tag)])
-> MultipartData tag
fromRaw (inputs, files) = MultipartData is fs
Expand Down Expand Up @@ -274,6 +280,9 @@ class ToMultipart tag a where
instance ToMultipart tag (MultipartData tag) where
toMultipart = id

instance (ToMultipart tag a, Foldable t) => ToMultipart tag (t a) where
toMultipart xs = foldMap toMultipart xs

-- | Upon seeing @MultipartForm a :> ...@ in an API type,
--- servant-server will hand a value of type @a@ to your handler
-- assuming the request body's content type is
Expand Down