on master help sign in
Remove the use of undefined in unfold scan

Also: * Remove trailing spaces * Remove stale comment * Remove some variables

commitca12b2e8da359331848f0d55cda03085de7c91a1 authorHarendra Kumar <harendra@composewell.com> dateSat 6 Nov 2021, 13:16 (5 years ago) parenta715053
1 file changed+10−14
src/Streamly/Internal/Data/Unfold.hs+10−14
src/Streamly/Internal/Data/Unfold.hs+10−14
@@ -423,8 +423,6 @@ either (Unfold step1 inject1) = Unfold step inject
423423 Skip s -> Skip (s, f)
424424 Stop -> Stop) <$> step1 st
425425
426−-- See StreamD.scanOnce for implementing this.
427−--
428426-- | Scan the output of an 'Unfold' to change it in a stateful manner.
429427--
430428-- /Pre-release/
@@ -436,28 +434,26 @@ scan (Fold stepF initial extract) (Unfold stepU injectU) =
436434 where
437435
438436 inject a = do
439− fs <- initial
440− case fs of
441− FL.Partial fs1 -> do
442− us <- injectU a
443− return (fs1, Just us)
444− FL.Done _ -> return (undefined, Nothing)
437+ r <- initial
438+ case r of
439+ FL.Partial fs -> Just . (fs,) <$> injectU a
440+ FL.Done _ -> return Nothing
445441
446442 {-# INLINE_LATE step #-}
447− step (fs, Just us) = do
443+ step (Just (fs, us)) = do
448444 ru <- stepU us
449445 case ru of
450446 Yield x s -> do
451447 rf <- stepF fs x
452448 case rf of
453− FL.Done v -> return $ Yield v (fs, Nothing)
449+ FL.Done v -> return $ Yield v Nothing
454450 FL.Partial fs1 -> do
455451 v <- extract fs1
456− return $ Yield v (fs1, Just s)
457− Skip s -> return $ Skip (fs, Just s)
452+ return $ Yield v (Just (fs1, s))
453+ Skip s -> return $ Skip (Just (fs, s))
458454 Stop -> return Stop
459−
460− step (_, Nothing) = return Stop
455+
456+ step Nothing = return Stop
461457
462458-- | Scan the output of an 'Unfold' to change it in a stateful manner.
463459--