Commits

Bryan O'Sullivan committed ac8b3c1

Implement replicate

  • Participants
  • Parent commits 0963495

Comments (0)

Files changed (2)

File Data/Text.hs

     , minimum
 
     -- * Construction
+    , replicate
     , unfoldr
     , unfoldrN
 
 -- -----------------------------------------------------------------------------
 -- ** Generating and unfolding 'Text's
 
+replicate :: Int -> Char -> Text
+replicate n c = unstream (S.replicate n c)
+{-# INLINE replicate #-}
+
 -- | /O(n)/, where @n@ is the length of the result. The 'unfoldr'
 -- function is analogous to the List 'L.unfoldr'. 'unfoldr' builds a
 -- 'Text' from a seed value. The function takes the element and

File Data/Text/Fusion.hs

     , minimum
 
     -- * Construction
+    , replicate
     , unfoldr
     , unfoldrN
 
     , zipWith
     ) where
 
-import Prelude hiding
-    (map, tail, head, foldr, filter, concat, last, init, null, length, foldl,
-     foldl1, foldr1, concatMap, any, all, maximum, minimum, take, drop,
-     takeWhile, dropWhile, elem, zipWith, reverse)
+import Prelude (Bool(..), Char, Either(..), Eq(..), Maybe(..), Monad(..),
+                Num(..), Ord(..), String, ($), (++), (.), (&&), error,
+                fromIntegral, fst, otherwise, snd)
 import Data.Char (ord)
 import Control.Monad (liftM2)
 import Control.Monad.ST (runST, ST)
 -- -----------------------------------------------------------------------------
 -- ** Generating and unfolding streams
 
+replicate :: Int -> Char -> Stream Char
+replicate n c = Stream next 0 n
+  where
+    {-# INLINE next #-}
+    next i | i >= n    = Done
+           | otherwise = Yield c (i + 1)
+{-# INLINE [0] replicate #-}
+
 -- | /O(n)/, where @n@ is the length of the result. The unfoldr function
 -- is analogous to the List 'unfoldr'. unfoldr builds a stream
 -- from a seed value. The function takes the element and returns