Skip to content

Commit 8018c00

Browse files
committed
Add (<*>+)
1 parent 3aebbc7 commit 8018c00

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

Data/Aeson/Types.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ module Data.Aeson.Types
3636
, ToJSON(..)
3737
, KeyValue(..)
3838
, liftP2
39+
, (<*>+)
3940
, modifyFailure
4041
, parserThrowError
4142
, parserCatchError

Data/Aeson/Types/Internal.hs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ module Data.Aeson.Types.Internal
4444
, parseEither
4545
, parseMaybe
4646
, liftP2
47+
, (<*>+)
4748
, modifyFailure
4849
, parserThrowError
4950
, parserCatchError
@@ -339,14 +340,22 @@ apP d e = do
339340
return (b a)
340341
{-# INLINE apP #-}
341342

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

352+
infixl 4 <*>+
353+
354+
-- | A variant of ('<*>') that lazily accumulates errors from both subparsers.
355+
(<*>+) :: Parser (a -> b) -> Parser a -> Parser b
356+
(<*>+) = liftP2 id
357+
{-# INLINE (<*>+) #-}
358+
350359
-- | A JSON \"object\" (key\/value map).
351360
type Object = HashMap Text Value
352361

0 commit comments

Comments
 (0)