]> gitweb @ CieloNegro.org - Lucu.git/blob - Network/HTTP/Lucu/Parser.hs
Reimplement MultipartForm
[Lucu.git] / Network / HTTP / Lucu / Parser.hs
1 {-# LANGUAGE
2     BangPatterns
3   , ScopedTypeVariables
4   , UnicodeSyntax
5   #-}
6 -- |This is an auxiliary parser utilities. You usually don't have to
7 -- use this module directly.
8 module Network.HTTP.Lucu.Parser
9     ( atMost
10     )
11     where
12 import Control.Applicative
13 import Control.Applicative.Unicode
14
15 -- |@'atMost' n v@ is like @'P.many' v@ but accumulates @v@ at most
16 -- @n@ times.
17 atMost ∷ Alternative f ⇒ Int → f a → f [a]
18 {-# INLINE atMost #-}
19 atMost 0 _ = pure []
20 atMost n v = ( (:) <$> v ⊛ atMost (n-1) v )
21              <|>
22              pure []