@@ -879,8 +879,8 @@ teeWithMin f (Fold stepL initialL extractL) (Fold stepR initialR extractR) =
879-- from the one which consumed least input i.e. take the shortest succeeding
879-- from the one which consumed least input i.e. take the shortest succeeding
882+-- If both the folds finish at the same time or if the result is extracted
882−-- If the result is extracted before any of the folds could finish then the
883+-- before any of the folds could finish then the left one is taken.
883−-- left one is taken.
885-- /Pre-release/
885-- /Pre-release/
@@ -906,75 +906,51 @@ shortest (Fold stepL initialL extractL) (Fold stepR initialR _) =
907 extract (Tuple' sL _) = Left <$> extractL sL
907 extract (Tuple' sL _) = Left <$> extractL sL
909−{-# ANN type LongestRunner Fuse #-}
909+{-# ANN type LongestState Fuse #-}
910−data LongestRunner sL sR bL bR
910+data LongestState sL sR
911− = LongestRunBoth !sL !sR
911+ = LongestBoth !sL !sR
912− | LongestRunLeft !sL !bR
912+ | LongestLeft !sL
913− | LongestRunRight !bL !sR
913+ | LongestRight !sR
915-- | Longest alternative. Apply both folds in parallel but choose the result
915-- | Longest alternative. Apply both folds in parallel but choose the result
916-- from the one which consumed more input i.e. take the longest succeeding
916-- from the one which consumed more input i.e. take the longest succeeding
919+-- If both the folds finish at the same time or if the result is extracted
920+-- before any of the folds could finish then the left one is taken.
919-- /Pre-release/
922-- /Pre-release/
921{-# INLINE longest #-}
924{-# INLINE longest #-}
922longest :: Monad m => Fold m x a -> Fold m x b -> Fold m x (Either a b)
925longest :: Monad m => Fold m x a -> Fold m x b -> Fold m x (Either a b)
923−longest (Fold stepL beginL doneL) (Fold stepR beginR doneR) =
926+longest (Fold stepL initialL extractL) (Fold stepR initialR extractR) =
924− Fold step begin done
927+ Fold step initial extract
928− begin = do
931+ {-# INLINE runBoth #-}
929− resL <- beginL
932+ runBoth actionL actionR = do
930− resR <- beginR
933+ resL <- actionL
932 case resL of
936 case resL of
933 Partial sL ->
937 Partial sL ->
934 Partial $
938 Partial $
935 case resR of
939 case resR of
936− Partial sR -> LongestRunBoth sL sR
940+ Partial sR -> LongestBoth sL sR
937− Done bR -> LongestRunLeft sL bR
941+ Done _ -> LongestLeft sL
938− Done bL ->
942+ Done bL -> bimap LongestRight (const (Left bL)) resR
940− Partial sR -> Partial $ LongestRunRight bL sR
941− Done bR -> Done $ Right bR
943− step (LongestRunBoth sL sR) a = do
944+ initial = runBoth initialL initialR
951− Partial sR1 -> LongestRunBoth sL1 sR1
952− Done bR -> LongestRunLeft sL1 bR
956− Partial sR1 -> Partial $ LongestRunRight bL sR1
957− Done bR -> Done $ Right bR
959− step (LongestRunLeft sL bR) a = do
963− Partial sL1 -> Partial $ LongestRunLeft sL1 bR
964− Done bL -> Done $ Left bL
966− step (LongestRunRight bL sR) a = do
970− Partial sR1 -> Partial $ LongestRunRight bL sR1
971− Done bR -> Done $ Right bR
973− done (LongestRunLeft sL _) = Left <$> doneL sL
975− done (LongestRunRight _ sR) = Right <$> doneR sR
946+ step (LongestBoth sL sR) a = runBoth (stepL sL a) (stepR sR a)
947+ step (LongestLeft sL) a = bimap LongestLeft Left <$> stepL sL a
948+ step (LongestRight sR) a = bimap LongestRight Right <$> stepR sR a
977− done (LongestRunBoth sL _) = Left <$> doneL sL
950+ left sL = Left <$> extractL sL
951+ extract (LongestLeft sL) = left sL
952+ extract (LongestRight sR) = Right <$> extractR sR
953+ extract (LongestBoth sL _) = left sL
979data ConcatMapState m sa a c
955data ConcatMapState m sa a c