on master help sign in
Rename rights, lefts, both to catRights, catLefts, catEithers (#2139)

Co-authored-by: Harendra Kumar <harendra@composewell.com>

commit001b87423449d14b0960ffb3d8b4749cdf78eddc authorRanjeet Ranjan <ranjeetr@composewell.com> dateThu 1 Dec 2022, 16:28 (4 years ago) parent9af539c
13 files changed+53−53
benchmark/Streamly/Benchmark/Data/Parser.hs+2−2 core/src/Streamly/Internal/Data/Fold.hs+3−3 core/src/Streamly/Internal/Data/Fold/Type.hs+12−12 core/src/Streamly/Internal/Data/Parser.hs+2−2 core/src/Streamly/Internal/Data/Stream/Reduce.hs+1−1 core/src/Streamly/Internal/Data/Stream/Top.hs+1−1 core/src/Streamly/Internal/Data/Stream/Transform.hs+15−15 src/Streamly/Internal/Data/Stream/IsStream/Top.hs−1 src/Streamly/Internal/FileSystem/Event/Darwin.hs+5−4 src/Streamly/Internal/FileSystem/Event/Linux.hs+1−1 test/Streamly/Test/Data/Parser.hs+7−7 test/Streamly/Test/Data/Parser/Chunked.hs+2−2 test/Streamly/Test/Data/Parser/ParserD.hs+2−2
benchmark/Streamly/Benchmark/Data/Parser.hs+2−2
@@ -409,7 +409,7 @@ parseMany :: Monad m => Int -> Stream m Int -> m ()
409409parseMany n =
410410 Stream.fold Fold.drain
411411 . 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)
413413 . fmap Sum
414414
415415{-# INLINE parseIterate #-}
@@ -417,7 +417,7 @@ parseIterate :: Monad m => Int -> Stream m Int -> m ()
417417parseIterate n =
418418 Stream.fold Fold.drain
419419 . fmap getSum
420− . Stream.rights
420+ . Stream.catRights
421421 . Stream.parseIterate
422422 (PR.fromFold . Fold.take n . Fold.sconcat)
423423 (Sum 0)
core/src/Streamly/Internal/Data/Fold.hs+3−3
@@ -207,9 +207,9 @@ module Streamly.Internal.Data.Fold
207207 , sampleFromthen
208208
209209 -- Either streams
210− , lefts
211− , rights
212− , both
210+ , catLefts
211+ , catRights
212+ , catEithers
213213
214214 {-
215215 -- ** Insertion
core/src/Streamly/Internal/Data/Fold/Type.hs+12−12
@@ -365,9 +365,9 @@ module Streamly.Internal.Data.Fold.Type
365365 , filter
366366 , filtering
367367 , filterM
368− , lefts
369− , rights
370− , both
368+ , catLefts
369+ , catRights
370+ , catEithers
371371
372372 -- ** Trimming
373373 , take
@@ -1290,17 +1290,17 @@ filterM f (Fold step begin done) = Fold step' begin done
12901290--
12911291-- /Pre-release/
12921292--
1293−{-# INLINE lefts #-}
1294−lefts :: (Monad m) => Fold m a c -> Fold m (Either a b) c
1295−lefts = filter isLeft . lmap (fromLeft undefined)
1293+{-# INLINE catLefts #-}
1294+catLefts :: (Monad m) => Fold m a c -> Fold m (Either a b) c
1295+catLefts = filter isLeft . lmap (fromLeft undefined)
12961296
12971297-- | Discard 'Left's and unwrap 'Right's in an 'Either' stream.
12981298--
12991299-- /Pre-release/
13001300--
1301−{-# INLINE rights #-}
1302−rights :: (Monad m) => Fold m b c -> Fold m (Either a b) c
1303−rights = filter isRight . lmap (fromRight undefined)
1301+{-# INLINE catRights #-}
1302+catRights :: (Monad m) => Fold m b c -> Fold m (Either a b) c
1303+catRights = filter isRight . lmap (fromRight undefined)
13041304
13051305-- | Remove the either wrapper and flatten both lefts and as well as rights in
13061306-- the output stream.
@@ -1311,9 +1311,9 @@ rights = filter isRight . lmap (fromRight undefined)
13111311--
13121312-- /Pre-release/
13131313--
1314−{-# INLINE both #-}
1315−both :: Fold m a b -> Fold m (Either a a) b
1316−both = lmap (either id id)
1314+{-# INLINE catEithers #-}
1315+catEithers :: Fold m a b -> Fold m (Either a a) b
1316+catEithers = lmap (either id id)
13171317
13181318------------------------------------------------------------------------------
13191319-- Parsing
core/src/Streamly/Internal/Data/Parser.hs+2−2
@@ -1481,7 +1481,7 @@ sepBy1 p sep sink = do
14811481-- run, when it is done content parser is run again and so on. If none of the
14821482-- parsers consumes an input then parser returns a failure.
14831483--
1484−-- >>> sepBy p1 p2 sink = Parser.deintercalate p1 p2 (Fold.lefts sink)
1484+-- >>> sepBy p1 p2 sink = Parser.deintercalate p1 p2 (Fold.catLefts sink)
14851485-- >>> sepBy content sep sink = Parser.sepBy1 content sep sink <|> return mempty
14861486--
14871487{-# INLINE sepBy #-}
@@ -1489,7 +1489,7 @@ sepBy :: Monad m =>
14891489 Parser a m b -> Parser a m x -> Fold m b c -> Parser a m c
14901490sepBy content sep sink =
14911491 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)
14931493
14941494-------------------------------------------------------------------------------
14951495-- Interleaving a collection of parsers
core/src/Streamly/Internal/Data/Stream/Reduce.hs+1−1
@@ -398,7 +398,7 @@ parseManyTill = undefined
398398--
399399-- >>> import Data.Monoid (Sum(..))
400400-- >>> 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
402402-- [3,10,21,36,55,55]
403403--
404404-- 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 =
119119 Fold.toStreamRev
120120 Fold.toStream
121121 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)
123123
124124------------------------------------------------------------------------------
125125-- SQL Joins
core/src/Streamly/Internal/Data/Stream/Transform.hs+15−15
@@ -132,9 +132,9 @@ module Streamly.Internal.Data.Stream.Transform
132132
133133 -- * Either Streams
134134 -- Move these to Streamly.Data.Either.Stream?
135− , lefts
136− , rights
137− , both
135+ , catLefts
136+ , catRights
137+ , catEithers
138138 )
139139where
140140
@@ -998,31 +998,31 @@ mapMaybeM f = fmap fromJust . filter isJust . mapM f
998998
999999-- | Discard 'Right's and unwrap 'Left's in an 'Either' stream.
10001000--
1001−-- >>> lefts = fmap (fromLeft undefined) . Stream.filter isLeft
1001+-- >>> catLefts = fmap (fromLeft undefined) . Stream.filter isLeft
10021002--
10031003-- /Pre-release/
10041004--
1005−{-# INLINE lefts #-}
1006−lefts :: Monad m => Stream m (Either a b) -> Stream m a
1007−lefts = fmap (fromLeft undefined) . filter isLeft
1005+{-# INLINE catLefts #-}
1006+catLefts :: Monad m => Stream m (Either a b) -> Stream m a
1007+catLefts = fmap (fromLeft undefined) . filter isLeft
10081008
10091009-- | Discard 'Left's and unwrap 'Right's in an 'Either' stream.
10101010--
1011−-- >>> rights = fmap (fromRight undefined) . Stream.filter isRight
1011+-- >>> catRights = fmap (fromRight undefined) . Stream.filter isRight
10121012--
10131013-- /Pre-release/
10141014--
1015−{-# INLINE rights #-}
1016−rights :: Monad m => Stream m (Either a b) -> Stream m b
1017−rights = fmap (fromRight undefined) . filter isRight
1015+{-# INLINE catRights #-}
1016+catRights :: Monad m => Stream m (Either a b) -> Stream m b
1017+catRights = fmap (fromRight undefined) . filter isRight
10181018
10191019-- | Remove the either wrapper and flatten both lefts and as well as rights in
10201020-- the output stream.
10211021--
1022−-- >>> both = fmap (either id id)
1022+-- >>> catEithers = fmap (either id id)
10231023--
10241024-- /Pre-release/
10251025--
1026−{-# INLINE both #-}
1027−both :: Monad m => Stream m (Either a a) -> Stream m a
1028−both = fmap (either id id)
1026+{-# INLINE catEithers #-}
1027+catEithers :: Monad m => Stream m (Either a a) -> Stream m a
1028+catEithers = fmap (either id id)
src/Streamly/Internal/Data/Stream/IsStream/Top.hs−1
@@ -252,7 +252,6 @@ sortBy cmp =
252252 in Stream.concatPairsWith (Stream.mergeBy cmp) id
253253 . Stream.rights . Stream.parseMany (fmap (either id id) p)
254254
255−
256255------------------------------------------------------------------------------
257256-- SQL Joins
258257------------------------------------------------------------------------------
src/Streamly/Internal/FileSystem/Event/Darwin.hs+5−4
@@ -180,8 +180,9 @@ import Streamly.Internal.Data.Array.Type (Array(..))
180180import System.IO (Handle, hClose)
181181
182182import qualified Data.List.NonEmpty as NonEmpty
183+import qualified Streamly.Data.Fold as FL
183184import 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
185186import qualified Streamly.Internal.Unicode.Stream as U
186187import qualified Streamly.Internal.FileSystem.Handle as FH
187188import qualified Streamly.Internal.Data.Array as A
@@ -505,7 +506,7 @@ readOneEvent = do
505506
506507watchToStream :: Watch -> Stream IO Event
507508watchToStream (Watch handle _ _) =
508− S.rights $ S.parseMany readOneEvent $ S.unfold FH.reader handle
509+ S.catRights $ S.parseMany readOneEvent $ S.unfold FH.reader handle
509510
510511-- XXX Write tests for all the points in macOS specific behavior.
511512--
@@ -560,7 +561,7 @@ watchToStream (Watch handle _ _) =
560561--
561562watchWith ::
562563 (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
564565
565566 where
566567
@@ -1036,7 +1037,7 @@ isLastHardLink = getFlag kFSEventStreamEventFlagItemIsLastHardlink
10361037-- | Convert an 'Event' record to a String representation.
10371038showEvent :: Event -> String
10381039showEvent 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
10401041 in "--------------------------"
10411042 ++ "\nId = " ++ show eventId
10421043 ++ "\nPath = " ++ show path
src/Streamly/Internal/FileSystem/Event/Linux.hs+1−1
@@ -868,7 +868,7 @@ watchToStream cfg wt@(Watch handle _) = do
868868 -- sizeof(struct inotify_event) + NAME_MAX + 1
869869 --
870870 -- 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
872872
873873-- XXX We should not go across the mount points of network file systems or file
874874-- systems that are known to not generate any events.
test/Streamly/Test/Data/Parser.hs+7−7
@@ -493,7 +493,7 @@ parseManyWordQuotedBy =
493493 spc _ = False
494494
495495 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
497497 H.it (showCase c) $ result `H.shouldBe` expected
498498
499499 where
@@ -610,8 +610,8 @@ deintercalate =
610610 p1 = P.takeWhile even FL.toList
611611 p2 = P.takeWhile odd FL.toList
612612 partition =
613− FL.tee (fmap concat $ FL.lefts FL.toList)
614− (fmap concat $ FL.rights FL.toList)
613+ FL.tee (fmap concat $ FL.catLefts FL.toList)
614+ (fmap concat $ FL.catRights FL.toList)
615615 p = P.deintercalate p1 p2 partition
616616
617617-- shortestPass :: Property
@@ -744,7 +744,7 @@ parseMany =
744744 let p = P.fromFold $ FL.take len FL.toList
745745 run
746746 $ S.fold FL.toList
747− $ S.rights
747+ $ S.catRights
748748 $ S.parseMany p (S.fromList $ concat ins)
749749 listEquals (==) outs ins
750750
@@ -799,7 +799,7 @@ parseMany2Events =
799799 xs <-
800800 ( run
801801 $ S.fold FL.toList
802− $ S.rights
802+ $ S.catRights
803803 $ S.parseMany readOneEvent
804804 $ S.fromList (concat (replicate 2 event))
805805 )
@@ -819,7 +819,7 @@ manyEqParseMany =
819819 monadicIO $ do
820820 let strm = S.fromList lst
821821 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
823823 return $
824824 case r1 of
825825 Right o1 -> o1 == r2
@@ -865,7 +865,7 @@ takeEndBy2 =
865865
866866 eitherParsedList =
867867 S.fold FL.toList
868− $ S.rights
868+ $ S.catRights
869869 $ S.parseMany (P.takeEndBy predicate prsr) strm
870870
871871 where
test/Streamly/Test/Data/Parser/Chunked.hs+2−2
@@ -606,8 +606,8 @@ deintercalate =
606606 p1 = P.takeWhile even FL.toList
607607 p2 = P.takeWhile odd FL.toList
608608 partition =
609− FL.tee (fmap concat $ FL.lefts FL.toList)
610− (fmap concat $ FL.rights FL.toList)
609+ FL.tee (fmap concat $ FL.catLefts FL.toList)
610+ (fmap concat $ FL.catRights FL.toList)
611611 p = P.deintercalate p1 p2 partition
612612
613613-- shortestPass :: Property
test/Streamly/Test/Data/Parser/ParserD.hs+2−2
@@ -640,7 +640,7 @@ parseMany =
640640 forAll (listOf (vectorOf len (chooseAny :: Gen Int))) $ \ ins ->
641641 monadicIO $ do
642642 outs <-
643− (toList $ S.rights $ S.parseManyD
643+ (toList $ S.catRights $ S.parseManyD
644644 (P.fromFold $ FL.take len FL.toList) (S.fromList $ concat ins)
645645 )
646646 return $ outs == ins
@@ -737,7 +737,7 @@ parseMany2Events =
737737 xs <-
738738 ( run
739739 $ toList
740− $ S.rights
740+ $ S.catRights
741741 $ S.parseManyD readOneEvent
742742 $ S.fromList (concat (replicate 2 event))
743743 )