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