@@ -774,6 +774,7 @@ teeWith f (Fold stepL initialL extractL) (Fold stepR initialR extractR) =
774774
775775 where
776776
777+ {-# INLINE runBoth #-}
777778 runBoth actionL actionR = do
778779 resL <- actionL
779780 resR <- actionR
@@ -813,6 +814,7 @@ teeWithFst f (Fold stepL initialL extractL) (Fold stepR initialR extractR) =
813814
814815 where
815816
817+ {-# INLINE runBoth #-}
816818 runBoth actionL actionR = do
817819 resL <- actionL
818820 resR <- actionR
@@ -844,51 +846,34 @@ teeWithFst f (Fold stepL initialL extractL) (Fold stepR initialR extractR) =
844846-- /Pre-release/
845847--
846848{-# INLINE teeWithMin #-}
847−teeWithMin :: Monad m => (b -> c -> d) -> Fold m a b -> Fold m a c -> Fold m a d
848−teeWithMin f (Fold stepL beginL doneL) (Fold stepR beginR doneR) =
849− Fold step begin done
849+teeWithMin :: Monad m =>
850+ (b -> c -> d) -> Fold m a b -> Fold m a c -> Fold m a d
851+teeWithMin f (Fold stepL initialL extractL) (Fold stepR initialR extractR) =
852+ Fold step initial extract
850853
851854 where
852855
853− begin = do
854− resL <- beginL
855− resR <- beginR
856+ {-# INLINE runBoth #-}
857+ runBoth actionL actionR = do
858+ resL <- actionL
859+ resR <- actionR
856860 case resL of
857− Partial sL1 -> do
861+ Partial sl -> do
858862 case resR of
859− Partial sR1 -> return $ Partial $ Tuple' sL1 sR1
860− Done br -> do
861− bl <- doneL sL1
862− return $ Done $ f bl br
863+ Partial sr -> return $ Partial $ Tuple' sl sr
864+ Done br -> Done . (`f` br) <$> extractL sl
863865
864866 Done bl -> do
865− case resR of
866− Partial sr -> do
867− br <- doneR sr
868− return $ Done $ f bl br
869− Done br -> return $ Done $ f bl br
867+ Done . f bl <$>
868+ case resR of
869+ Partial sr -> extractR sr
870+ Done br -> return br
870871
871− step (Tuple' sL sR) a = do
872− resL <- stepL sL a
873− resR <- stepR sR a
874− case resL of
875− Partial sL1 ->
876− case resR of
877− Partial sR1 -> return $ Partial $ Tuple' sL1 sR1
878− Done bR -> do
879− bL <- doneL sL1
880− return $ Done $ f bL bR
881− Done bL ->
882− case resR of
883− Partial sR1 -> do
884− br <- doneR sR1
885− return $ Done $ f bL br
886− Done bR -> return $ Done $ f bL bR
887−
888− done (Tuple' sL sR) = do
889− bL <- doneL sL
890− bR <- doneR sR
891− return $ f bL bR
872+ initial = runBoth initialL initialR
873+
874+ step (Tuple' sL sR) a = runBoth (stepL sL a) (stepR sR a)
875+
876+ extract (Tuple' sL sR) = f <$> extractL sL <*> extractR sR
892877
893878-- | Shortest alternative. Apply both folds in parallel but choose the result
894879-- from the one which consumed least input i.e. take the shortest succeeding