on master help sign in
Add Parser.choice
commit32eace28a85a18b4c2d61bd5d9106ec98803ab32 authorAdithya Kumar <adithya@composewell.com> dateSun 1 Aug 2021, 23:20 (5 years ago) parent8c3e71a
2 files changed+7−10
src/Streamly/Internal/Data/Parser.hs+3−4 src/Streamly/Internal/Data/Parser/ParserD.hs+4−6
src/Streamly/Internal/Data/Parser.hs+3−4
@@ -946,13 +946,12 @@ concatMap f p = K.toParserK $ D.concatMap (K.fromParserK . f) (K.fromParserK p)
946946--
947947-- This is same as 'asum' but more efficient.
948948--
949−-- /Unimplemented/
949+-- /Broken/
950950--
951951{-# INLINE choice #-}
952952choice ::
953− -- Foldable t =>
954− t (Parser m a b) -> Parser m a b
955−choice _ps = undefined
953+ (Functor t, Foldable t, MonadCatch m) => t (Parser m a b) -> Parser m a b
954+choice ps = K.toParserK $ D.choice $ K.fromParserK <$> ps
956955
957956-------------------------------------------------------------------------------
958957-- Sequential Repetition
src/Streamly/Internal/Data/Parser/ParserD.hs+4−6
@@ -942,16 +942,14 @@ sequence _f _p = undefined
942942-------------------------------------------------------------------------------
943943-- Alternative Collection
944944-------------------------------------------------------------------------------
945−--
945+
946946-- | See 'Streamly.Internal.Data.Parser.choice'.
947947--
948−-- /Unimplemented/
948+-- /Broken/
949949--
950950{-# INLINE choice #-}
951−choice ::
952− -- Foldable t =>
953− t (Parser m a b) -> Parser m a b
954−choice _ps = undefined
951+choice :: (MonadCatch m, Foldable t) => t (Parser m a b) -> Parser m a b
952+choice = foldl1 shortest
955953
956954-------------------------------------------------------------------------------
957955-- Sequential Repetition