on master help sign in
Rename rights, lefts, both to catRights, catLefts, catEithers (#2139)
001b874Ranjeet Ranjan
benchmark/Streamly/Benchmark/Data/Parser.hs+2−2
@@ -409,7 +409,7 @@ parseMany :: Monad m => Int -> Stream m Int -> m ()
409parseMany n =
409parseMany n =
410 Stream.fold Fold.drain
410 Stream.fold Fold.drain
411 . fmap getSum
411 . fmap getSum
412− . Stream.rights . Stream.parseMany (PR.fromFold $ Fold.take n Fold.mconcat)
412+ . Stream.catRights . Stream.parseMany (PR.fromFold $ Fold.take n Fold.mconcat)
413 . fmap Sum
413 . fmap Sum
414
414
415{-# INLINE parseIterate #-}
415{-# INLINE parseIterate #-}
@@ -417,7 +417,7 @@ parseIterate :: Monad m => Int -> Stream m Int -> m ()
417parseIterate n =
417parseIterate n =
418 Stream.fold Fold.drain
418 Stream.fold Fold.drain
419 . fmap getSum
419 . fmap getSum
420− . Stream.rights
420+ . Stream.catRights
421 . Stream.parseIterate
421 . Stream.parseIterate
422 (PR.fromFold . Fold.take n . Fold.sconcat)
422 (PR.fromFold . Fold.take n . Fold.sconcat)
423 (Sum 0)
423 (Sum 0)
core/src/Streamly/Internal/Data/Fold.hs+3−3
@@ -207,9 +207,9 @@ module Streamly.Internal.Data.Fold
207 , sampleFromthen
207 , sampleFromthen
208
208
209 -- Either streams
209 -- Either streams
210− , lefts
210+ , catLefts
211− , rights
211+ , catRights
212− , both
212+ , catEithers
213
213
214 {-
214 {-
215 -- ** Insertion
215 -- ** Insertion
core/src/Streamly/Internal/Data/Fold/Type.hs+12−12
@@ -365,9 +365,9 @@ module Streamly.Internal.Data.Fold.Type
365 , filter
365 , filter
366 , filtering
366 , filtering
367 , filterM
367 , filterM
368− , lefts
368+ , catLefts
369− , rights
369+ , catRights
370− , both
370+ , catEithers
371
371
372 -- ** Trimming
372 -- ** Trimming
373 , take
373 , take
@@ -1290,17 +1290,17 @@ filterM f (Fold step begin done) = Fold step' begin done
1290--
1290--
1291-- /Pre-release/
1291-- /Pre-release/
1292--
1292--
1293−{-# INLINE lefts #-}
1293+{-# INLINE catLefts #-}
1294−lefts :: (Monad m) => Fold m a c -> Fold m (Either a b) c
1294+catLefts :: (Monad m) => Fold m a c -> Fold m (Either a b) c
1295−lefts = filter isLeft . lmap (fromLeft undefined)
1295+catLefts = filter isLeft . lmap (fromLeft undefined)
1296
1296
1297-- | Discard 'Left's and unwrap 'Right's in an 'Either' stream.
1297-- | Discard 'Left's and unwrap 'Right's in an 'Either' stream.
1298--
1298--
1299-- /Pre-release/
1299-- /Pre-release/
1300--
1300--
1301−{-# INLINE rights #-}
1301+{-# INLINE catRights #-}
1302−rights :: (Monad m) => Fold m b c -> Fold m (Either a b) c
1302+catRights :: (Monad m) => Fold m b c -> Fold m (Either a b) c
1303−rights = filter isRight . lmap (fromRight undefined)
1303+catRights = filter isRight . lmap (fromRight undefined)
1304
1304
1305-- | Remove the either wrapper and flatten both lefts and as well as rights in
1305-- | Remove the either wrapper and flatten both lefts and as well as rights in
1306-- the output stream.
1306-- the output stream.
@@ -1311,9 +1311,9 @@ rights = filter isRight . lmap (fromRight undefined)
1311--
1311--
1312-- /Pre-release/
1312-- /Pre-release/
1313--
1313--
1314−{-# INLINE both #-}
1314+{-# INLINE catEithers #-}
1315−both :: Fold m a b -> Fold m (Either a a) b
1315+catEithers :: Fold m a b -> Fold m (Either a a) b
1316−both = lmap (either id id)
1316+catEithers = lmap (either id id)
1317
1317
1318------------------------------------------------------------------------------
1318------------------------------------------------------------------------------
1319-- Parsing
1319-- Parsing
core/src/Streamly/Internal/Data/Parser.hs+2−2
@@ -1481,7 +1481,7 @@ sepBy1 p sep sink = do
1481-- run, when it is done content parser is run again and so on. If none of the
1481-- run, when it is done content parser is run again and so on. If none of the
1482-- parsers consumes an input then parser returns a failure.
1482-- parsers consumes an input then parser returns a failure.
1483--
1483--
1484−-- >>> sepBy p1 p2 sink = Parser.deintercalate p1 p2 (Fold.lefts sink)
1484+-- >>> sepBy p1 p2 sink = Parser.deintercalate p1 p2 (Fold.catLefts sink)
1485-- >>> sepBy content sep sink = Parser.sepBy1 content sep sink <|> return mempty
1485-- >>> sepBy content sep sink = Parser.sepBy1 content sep sink <|> return mempty
1486--
1486--
1487{-# INLINE sepBy #-}
1487{-# INLINE sepBy #-}
@@ -1489,7 +1489,7 @@ sepBy :: Monad m =>
1489 Parser a m b -> Parser a m x -> Fold m b c -> Parser a m c
1489 Parser a m b -> Parser a m x -> Fold m b c -> Parser a m c
1490sepBy content sep sink =
1490sepBy content sep sink =
1491 D.toParserK $ D.sepBy (D.fromParserK content) (D.fromParserK sep) sink
1491 D.toParserK $ D.sepBy (D.fromParserK content) (D.fromParserK sep) sink
1492−-- sepBy sink = deintercalate (FL.lefts sink)
1492+-- sepBy sink = deintercalate (FL.catLefts sink)
1493
1493
1494-------------------------------------------------------------------------------
1494-------------------------------------------------------------------------------
1495-- Interleaving a collection of parsers
1495-- Interleaving a collection of parsers
core/src/Streamly/Internal/Data/Stream/Reduce.hs+1−1
@@ -398,7 +398,7 @@ parseManyTill = undefined
398--
398--
399-- >>> import Data.Monoid (Sum(..))
399-- >>> import Data.Monoid (Sum(..))
400-- >>> s = Stream.fromList [1..10]
400-- >>> s = Stream.fromList [1..10]
401−-- >>> Stream.fold Fold.toList $ fmap getSum $ Stream.rights $ Stream.parseIterate (\b -> Parser.takeBetween 0 2 (Fold.sconcat b)) (Sum 0) $ fmap Sum s
401+-- >>> Stream.fold Fold.toList $ fmap getSum $ Stream.catRights $ Stream.parseIterate (\b -> Parser.takeBetween 0 2 (Fold.sconcat b)) (Sum 0) $ fmap Sum s
402-- [3,10,21,36,55,55]
402-- [3,10,21,36,55,55]
403--
403--
404-- This is the streaming equivalent of monad like sequenced application of
404-- This is the streaming equivalent of monad like sequenced application of
core/src/Streamly/Internal/Data/Stream/Top.hs+1−1
@@ -119,7 +119,7 @@ sortBy cmp =
119 Fold.toStreamRev
119 Fold.toStreamRev
120 Fold.toStream
120 Fold.toStream
121 in Stream.concatPairsWith (Stream.mergeBy cmp) id
121 in Stream.concatPairsWith (Stream.mergeBy cmp) id
122− . Stream.rights . Stream.parseMany (fmap (either id id) p)
122+ . Stream.catRights . Stream.parseMany (fmap (either id id) p)
123
123
124------------------------------------------------------------------------------
124------------------------------------------------------------------------------
125-- SQL Joins
125-- SQL Joins
core/src/Streamly/Internal/Data/Stream/Transform.hs+15−15
@@ -132,9 +132,9 @@ module Streamly.Internal.Data.Stream.Transform
132
132
133 -- * Either Streams
133 -- * Either Streams
134 -- Move these to Streamly.Data.Either.Stream?
134 -- Move these to Streamly.Data.Either.Stream?
135− , lefts
135+ , catLefts
136− , rights
136+ , catRights
137− , both
137+ , catEithers
138 )
138 )
139where
139where
140
140
@@ -998,31 +998,31 @@ mapMaybeM f = fmap fromJust . filter isJust . mapM f
998
998
999-- | Discard 'Right's and unwrap 'Left's in an 'Either' stream.
999-- | Discard 'Right's and unwrap 'Left's in an 'Either' stream.
1000--
1000--
1001−-- >>> lefts = fmap (fromLeft undefined) . Stream.filter isLeft
1001+-- >>> catLefts = fmap (fromLeft undefined) . Stream.filter isLeft
1002--
1002--
1003-- /Pre-release/
1003-- /Pre-release/
1004--
1004--
1005−{-# INLINE lefts #-}
1005+{-# INLINE catLefts #-}
1006−lefts :: Monad m => Stream m (Either a b) -> Stream m a
1006+catLefts :: Monad m => Stream m (Either a b) -> Stream m a
1007−lefts = fmap (fromLeft undefined) . filter isLeft
1007+catLefts = fmap (fromLeft undefined) . filter isLeft
1008
1008
1009-- | Discard 'Left's and unwrap 'Right's in an 'Either' stream.
1009-- | Discard 'Left's and unwrap 'Right's in an 'Either' stream.
1010--
1010--
1011−-- >>> rights = fmap (fromRight undefined) . Stream.filter isRight
1011+-- >>> catRights = fmap (fromRight undefined) . Stream.filter isRight
1012--
1012--
1013-- /Pre-release/
1013-- /Pre-release/
1014--
1014--
1015−{-# INLINE rights #-}
1015+{-# INLINE catRights #-}
1016−rights :: Monad m => Stream m (Either a b) -> Stream m b
1016+catRights :: Monad m => Stream m (Either a b) -> Stream m b
1017−rights = fmap (fromRight undefined) . filter isRight
1017+catRights = fmap (fromRight undefined) . filter isRight
1018
1018
1019-- | Remove the either wrapper and flatten both lefts and as well as rights in
1019-- | Remove the either wrapper and flatten both lefts and as well as rights in
1020-- the output stream.
1020-- the output stream.
1021--
1021--
1022−-- >>> both = fmap (either id id)
1022+-- >>> catEithers = fmap (either id id)
1023--
1023--
1024-- /Pre-release/
1024-- /Pre-release/
1025--
1025--
1026−{-# INLINE both #-}
1026+{-# INLINE catEithers #-}
1027−both :: Monad m => Stream m (Either a a) -> Stream m a
1027+catEithers :: Monad m => Stream m (Either a a) -> Stream m a
1028−both = fmap (either id id)
1028+catEithers = fmap (either id id)
src/Streamly/Internal/Data/Stream/IsStream/Top.hs−1
@@ -252,7 +252,6 @@ sortBy cmp =
252 in Stream.concatPairsWith (Stream.mergeBy cmp) id
252 in Stream.concatPairsWith (Stream.mergeBy cmp) id
253 . Stream.rights . Stream.parseMany (fmap (either id id) p)
253 . Stream.rights . Stream.parseMany (fmap (either id id) p)
254
254
255−
256------------------------------------------------------------------------------
255------------------------------------------------------------------------------
257-- SQL Joins
256-- SQL Joins
258------------------------------------------------------------------------------
257------------------------------------------------------------------------------
src/Streamly/Internal/FileSystem/Event/Darwin.hs+5−4
@@ -180,8 +180,9 @@ import Streamly.Internal.Data.Array.Type (Array(..))
180import System.IO (Handle, hClose)
180import System.IO (Handle, hClose)
181
181
182import qualified Data.List.NonEmpty as NonEmpty
182import qualified Data.List.NonEmpty as NonEmpty
183+import qualified Streamly.Data.Fold as FL
183import qualified Streamly.Internal.Data.Parser as PR
184import qualified Streamly.Internal.Data.Parser as PR
184−import qualified Streamly.Internal.Data.Stream.IsStream as S
185+import qualified Streamly.Internal.Data.Stream as S
185import qualified Streamly.Internal.Unicode.Stream as U
186import qualified Streamly.Internal.Unicode.Stream as U
186import qualified Streamly.Internal.FileSystem.Handle as FH
187import qualified Streamly.Internal.FileSystem.Handle as FH
187import qualified Streamly.Internal.Data.Array as A
188import qualified Streamly.Internal.Data.Array as A
@@ -505,7 +506,7 @@ readOneEvent = do
505
506
506watchToStream :: Watch -> Stream IO Event
507watchToStream :: Watch -> Stream IO Event
507watchToStream (Watch handle _ _) =
508watchToStream (Watch handle _ _) =
508− S.rights $ S.parseMany readOneEvent $ S.unfold FH.reader handle
509+ S.catRights $ S.parseMany readOneEvent $ S.unfold FH.reader handle
509
510
510-- XXX Write tests for all the points in macOS specific behavior.
511-- XXX Write tests for all the points in macOS specific behavior.
511--
512--
@@ -560,7 +561,7 @@ watchToStream (Watch handle _ _) =
560--
561--
561watchWith ::
562watchWith ::
562 (Config -> Config) -> NonEmpty (Array Word8) -> Stream IO Event
563 (Config -> Config) -> NonEmpty (Array Word8) -> Stream IO Event
563−watchWith f paths = S.bracket before after watchToStream
564+watchWith f paths = S.bracketIO before after watchToStream
564
565
565 where
566 where
566
567
@@ -1036,7 +1037,7 @@ isLastHardLink = getFlag kFSEventStreamEventFlagItemIsLastHardlink
1036-- | Convert an 'Event' record to a String representation.
1037-- | Convert an 'Event' record to a String representation.
1037showEvent :: Event -> String
1038showEvent :: Event -> String
1038showEvent ev@Event{..} =
1039showEvent ev@Event{..} =
1039− let path = runIdentity $ S.toList $ U.decodeUtf8' $ A.toStream eventAbsPath
1040+ let path = runIdentity $ S.fold FL.toList $ U.decodeUtf8' $ A.toStream eventAbsPath
1040 in "--------------------------"
1041 in "--------------------------"
1041 ++ "\nId = " ++ show eventId
1042 ++ "\nId = " ++ show eventId
1042 ++ "\nPath = " ++ show path
1043 ++ "\nPath = " ++ show path
src/Streamly/Internal/FileSystem/Event/Linux.hs+1−1
@@ -868,7 +868,7 @@ watchToStream cfg wt@(Watch handle _) = do
868 -- sizeof(struct inotify_event) + NAME_MAX + 1
868 -- sizeof(struct inotify_event) + NAME_MAX + 1
869 --
869 --
870 -- will be sufficient to read at least one event.
870 -- will be sufficient to read at least one event.
871− S.rights $ S.parseMany (readOneEvent cfg wt) $ S.unfold FH.reader handle
871+ S.catRights $ S.parseMany (readOneEvent cfg wt) $ S.unfold FH.reader handle
872
872
873-- XXX We should not go across the mount points of network file systems or file
873-- XXX We should not go across the mount points of network file systems or file
874-- systems that are known to not generate any events.
874-- systems that are known to not generate any events.
test/Streamly/Test/Data/Parser.hs+7−7
@@ -493,7 +493,7 @@ parseManyWordQuotedBy =
493 spc _ = False
493 spc _ = False
494
494
495 parser = P.wordQuotedBy kQ esc lQ rQ fromLQ spc FL.toList
495 parser = P.wordQuotedBy kQ esc lQ rQ fromLQ spc FL.toList
496− result <- H.runIO $ S.fold FL.toList $ S.rights $ S.parseMany parser inpStrm
496+ result <- H.runIO $ S.fold FL.toList $ S.catRights $ S.parseMany parser inpStrm
497 H.it (showCase c) $ result `H.shouldBe` expected
497 H.it (showCase c) $ result `H.shouldBe` expected
498
498
499 where
499 where
@@ -610,8 +610,8 @@ deintercalate =
610 p1 = P.takeWhile even FL.toList
610 p1 = P.takeWhile even FL.toList
611 p2 = P.takeWhile odd FL.toList
611 p2 = P.takeWhile odd FL.toList
612 partition =
612 partition =
613− FL.tee (fmap concat $ FL.lefts FL.toList)
613+ FL.tee (fmap concat $ FL.catLefts FL.toList)
614− (fmap concat $ FL.rights FL.toList)
614+ (fmap concat $ FL.catRights FL.toList)
615 p = P.deintercalate p1 p2 partition
615 p = P.deintercalate p1 p2 partition
616
616
617-- shortestPass :: Property
617-- shortestPass :: Property
@@ -744,7 +744,7 @@ parseMany =
744 let p = P.fromFold $ FL.take len FL.toList
744 let p = P.fromFold $ FL.take len FL.toList
745 run
745 run
746 $ S.fold FL.toList
746 $ S.fold FL.toList
747− $ S.rights
747+ $ S.catRights
748 $ S.parseMany p (S.fromList $ concat ins)
748 $ S.parseMany p (S.fromList $ concat ins)
749 listEquals (==) outs ins
749 listEquals (==) outs ins
750
750
@@ -799,7 +799,7 @@ parseMany2Events =
799 xs <-
799 xs <-
800 ( run
800 ( run
801 $ S.fold FL.toList
801 $ S.fold FL.toList
802− $ S.rights
802+ $ S.catRights
803 $ S.parseMany readOneEvent
803 $ S.parseMany readOneEvent
804 $ S.fromList (concat (replicate 2 event))
804 $ S.fromList (concat (replicate 2 event))
805 )
805 )
@@ -819,7 +819,7 @@ manyEqParseMany =
819 monadicIO $ do
819 monadicIO $ do
820 let strm = S.fromList lst
820 let strm = S.fromList lst
821 r1 <- run $ S.parse (P.many (split i) FL.toList) strm
821 r1 <- run $ S.parse (P.many (split i) FL.toList) strm
822− r2 <- run $ S.fold FL.toList $ S.rights $ S.parseMany (split i) strm
822+ r2 <- run $ S.fold FL.toList $ S.catRights $ S.parseMany (split i) strm
823 return $
823 return $
824 case r1 of
824 case r1 of
825 Right o1 -> o1 == r2
825 Right o1 -> o1 == r2
@@ -865,7 +865,7 @@ takeEndBy2 =
865
865
866 eitherParsedList =
866 eitherParsedList =
867 S.fold FL.toList
867 S.fold FL.toList
868− $ S.rights
868+ $ S.catRights
869 $ S.parseMany (P.takeEndBy predicate prsr) strm
869 $ S.parseMany (P.takeEndBy predicate prsr) strm
870
870
871 where
871 where
test/Streamly/Test/Data/Parser/Chunked.hs+2−2
@@ -606,8 +606,8 @@ deintercalate =
606 p1 = P.takeWhile even FL.toList
606 p1 = P.takeWhile even FL.toList
607 p2 = P.takeWhile odd FL.toList
607 p2 = P.takeWhile odd FL.toList
608 partition =
608 partition =
609− FL.tee (fmap concat $ FL.lefts FL.toList)
609+ FL.tee (fmap concat $ FL.catLefts FL.toList)
610− (fmap concat $ FL.rights FL.toList)
610+ (fmap concat $ FL.catRights FL.toList)
611 p = P.deintercalate p1 p2 partition
611 p = P.deintercalate p1 p2 partition
612
612
613-- shortestPass :: Property
613-- shortestPass :: Property
test/Streamly/Test/Data/Parser/ParserD.hs+2−2
@@ -640,7 +640,7 @@ parseMany =
640 forAll (listOf (vectorOf len (chooseAny :: Gen Int))) $ \ ins ->
640 forAll (listOf (vectorOf len (chooseAny :: Gen Int))) $ \ ins ->
641 monadicIO $ do
641 monadicIO $ do
642 outs <-
642 outs <-
643− (toList $ S.rights $ S.parseManyD
643+ (toList $ S.catRights $ S.parseManyD
644 (P.fromFold $ FL.take len FL.toList) (S.fromList $ concat ins)
644 (P.fromFold $ FL.take len FL.toList) (S.fromList $ concat ins)
645 )
645 )
646 return $ outs == ins
646 return $ outs == ins
@@ -737,7 +737,7 @@ parseMany2Events =
737 xs <-
737 xs <-
738 ( run
738 ( run
739 $ toList
739 $ toList
740− $ S.rights
740+ $ S.catRights
741 $ S.parseManyD readOneEvent
741 $ S.parseManyD readOneEvent
742 $ S.fromList (concat (replicate 2 event))
742 $ S.fromList (concat (replicate 2 event))
743 )
743 )