on master help sign in
Add Parser.choice
32eace2Adithya Kumar
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)
946--
946--
947-- This is same as 'asum' but more efficient.
947-- This is same as 'asum' but more efficient.
948--
948--
949−-- /Unimplemented/
949+-- /Broken/
950--
950--
951{-# INLINE choice #-}
951{-# INLINE choice #-}
952choice ::
952choice ::
953− -- Foldable t =>
954− t (Parser m a b) -> Parser m a b
953+ (Functor t, Foldable t, MonadCatch m) => t (Parser m a b) -> Parser m a b
955−choice _ps = undefined
954+choice ps = K.toParserK $ D.choice $ K.fromParserK <$> ps
956
955
957-------------------------------------------------------------------------------
956-------------------------------------------------------------------------------
958-- Sequential Repetition
957-- Sequential Repetition
src/Streamly/Internal/Data/Parser/ParserD.hs+4−6
@@ -942,16 +942,14 @@ sequence _f _p = undefined
942-------------------------------------------------------------------------------
942-------------------------------------------------------------------------------
943-- Alternative Collection
943-- Alternative Collection
944-------------------------------------------------------------------------------
944-------------------------------------------------------------------------------
945−--
945+
946-- | See 'Streamly.Internal.Data.Parser.choice'.
946-- | See 'Streamly.Internal.Data.Parser.choice'.
947--
947--
948−-- /Unimplemented/
948+-- /Broken/
949--
949--
950{-# INLINE choice #-}
950{-# INLINE choice #-}
951−choice ::
952− -- Foldable t =>
953− t (Parser m a b) -> Parser m a b
951+choice :: (MonadCatch m, Foldable t) => t (Parser m a b) -> Parser m a b
954−choice _ps = undefined
952+choice = foldl1 shortest
955
953
956-------------------------------------------------------------------------------
954-------------------------------------------------------------------------------
957-- Sequential Repetition
955-- Sequential Repetition