# Pastebin vhNbTLNJ {-# LANGUAGE BlockArguments #-} {-# LANGUAGE LambdaCase #-} {-# OPTIONS_GHC -Wall #-} import Data.Conduit import Data.Function (fix) data A data B data C f :: A -> Either B C f = undefined fc :: Monad m => ConduitT A C m (Maybe B) fc = fix $ \loop -> do await >>= \case Nothing -> (pure Nothing) Just a -> case f a of Left b -> pure (Just b) Right c -> yield c *> loop fc' :: Monad m => ConduitT A C m (Maybe B) fc' = fix $ \loop -> await >>= maybe (pure Nothing) (either (pure . Just) ((*> loop) . yield) . f)