Skip to content

Commit

Permalink
Add (<*>+)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lysxia committed Oct 8, 2017
1 parent 3aebbc7 commit 8018c00
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions Data/Aeson/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ module Data.Aeson.Types
, ToJSON(..)
, KeyValue(..)
, liftP2
, (<*>+)
, modifyFailure
, parserThrowError
, parserCatchError
Expand Down
11 changes: 10 additions & 1 deletion Data/Aeson/Types/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ module Data.Aeson.Types.Internal
, parseEither
, parseMaybe
, liftP2
, (<*>+)
, modifyFailure
, parserThrowError
, parserCatchError
Expand Down Expand Up @@ -339,14 +340,22 @@ apP d e = do
return (b a)
{-# INLINE apP #-}

-- | A variant of 'liftA2' that lazily accumulates errors from both subparsers.
-- | A variant of 'Control.Applicative.liftA2' that lazily accumulates errors
-- from both subparsers.
liftP2 :: (a -> b -> c) -> Parser a -> Parser b -> Parser c
liftP2 f pa pb = Parser $ \path kf ks ->
runParser pa path
(\(e :| es) -> kf (e :| es ++ runParser pb path NonEmpty.toList (const [])))
(\a -> runParser pb path kf (\b -> ks (f a b)))
{-# INLINE liftP2 #-}

infixl 4 <*>+

-- | A variant of ('<*>') that lazily accumulates errors from both subparsers.
(<*>+) :: Parser (a -> b) -> Parser a -> Parser b
(<*>+) = liftP2 id
{-# INLINE (<*>+) #-}

-- | A JSON \"object\" (key\/value map).
type Object = HashMap Text Value

Expand Down

0 comments on commit 8018c00

Please sign in to comment.