@@ -104,6 +104,7 @@ module Streamly.Internal.Prelude
104104 -- -- | Folds that extract selected elements of a stream or their properties.
105105 , (!!)
106106 , head
107+ , headElse
107108 , findM
108109 , find
109110 , lookup
@@ -1115,6 +1116,15 @@ null = S.null . toStreamS
11151116head :: Monad m => SerialT m a -> m (Maybe a)
11161117head = S.head . toStreamS
11171118
1119+-- | Extract the first element of the stream, if any, otherwise use the
1120+-- supplied default value. It can help avoid one branch in high performance
1121+-- code.
1122+--
1123+-- /Internal/
1124+{-# INLINE headElse #-}
1125+headElse :: Monad m => a -> SerialT m a -> m a
1126+headElse x = D.headElse x . toStreamD
1127+
11181128-- |
11191129-- > tail = fmap (fmap snd) . uncons
11201130--