@@ -79,6 +79,9 @@ module Data.Text.Fusion
7979 , takeWhile
8080 , dropWhile
8181
82+ -- * Predicates
83+ , isPrefixOf
84+
8285 -- * Searching
8386 , elem
8487 , filter
@@ -683,6 +686,19 @@ dropWhile p (Stream next0 s0 len) = Stream next (S1 :!: s0) len
683686 Yield x s' -> Yield x (S2 :!: s')
684687{-# INLINE [0] dropWhile #-}
685688
689+isPrefixOf :: (Eq a) => Stream a -> Stream a -> Bool
690+isPrefixOf (Stream next1 s1 _) (Stream next2 s2 _) = loop (next1 s1) (next2 s2)
691+ where
692+ loop Done _ = True
693+ loop _ Done = False
694+ loop (Skip s1') (Skip s2') = loop (next1 s1') (next2 s2')
695+ loop (Skip s1') x2 = loop (next1 s1') x2
696+ loop x1 (Skip s2') = loop x1 (next2 s2')
697+ loop (Yield x1 s1') (Yield x2 s2') = x1 == x2 &&
698+ loop (next1 s1') (next2 s2')
699+{-# INLINE [0] isPrefixOf #-}
700+{-# SPECIALISE isPrefixOf :: Stream Char -> Stream Char -> Bool #-}
701+
686702-- ----------------------------------------------------------------------------
687703-- * Searching
688704
@@ -811,5 +827,6 @@ zipWith f (Stream next0 sa0 len1) (Stream next1 sb0 len2) = Stream next (sa0 :!:
811827 Yield b sb' -> Yield (f a b) (sa' :!: sb' :!: Nothing)
812828{-# INLINE [0] zipWith #-}
813829
830+
814831errorEmptyList :: String -> a
815832errorEmptyList fun = error ("Data.Text.Fusion." ++ fun ++ ": empty list")