@@ -879,40 +879,32 @@ teeWithMin f (Fold stepL initialL extractL) (Fold stepR initialR extractR) =
879879-- from the one which consumed least input i.e. take the shortest succeeding
880880-- fold.
881881--
882+-- If the result is extracted before any of the folds could finish then the
883+-- left one is taken.
884+--
882885-- /Pre-release/
883886--
884887{-# INLINE shortest #-}
885888shortest :: Monad m => Fold m x a -> Fold m x b -> Fold m x (Either a b)
886−shortest (Fold stepL beginL doneL) (Fold stepR beginR _) =
887− Fold step begin done
889+shortest (Fold stepL initialL extractL) (Fold stepR initialR _) =
890+ Fold step initial extract
888891
889892 where
890893
891− begin = do
892− resL <- beginL
893− resR <- beginR
894+ {-# INLINE runBoth #-}
895+ runBoth actionL actionR = do
896+ resL <- actionL
897+ resR <- actionR
894898 return $
895899 case resL of
896− Partial sL ->
897− case resR of
898− Partial sR -> Partial $ Tuple' sL sR
899− Done bR -> Done $ Right bR
900+ Partial sL -> bimap (Tuple' sL) Right resR
900901 Done bL -> Done $ Left bL
901902
902− step (Tuple' sL sR) a = do
903− resL <- stepL sL a
904− resR <- stepR sR a
905− return $
906− case resL of
907− Partial sL1 ->
908− case resR of
909− Partial sR1 -> Partial $ Tuple' sL1 sR1
910− Done bR -> Done $ Right bR
911− Done bL -> Done $ Left bL
903+ initial = runBoth initialL initialR
904+
905+ step (Tuple' sL sR) a = runBoth (stepL sL a) (stepR sR a)
912906
913− done (Tuple' sL _) = do
914− x <- doneL sL
915− return $ Left x
907+ extract (Tuple' sL _) = Left <$> extractL sL
916908
917909{-# ANN type LongestRunner Fuse #-}
918910data LongestRunner sL sR bL bR