on master help sign in
Implement replicate
fa5c09fBryan O'Sullivan
Data/Text.hs+5
@@ -72,6 +72,7 @@ module Data.Text
72 , minimum
72 , minimum
73
73
74 -- * Construction
74 -- * Construction
75+ , replicate
75 , unfoldr
76 , unfoldr
76 , unfoldrN
77 , unfoldrN
77
78
@@ -425,6 +426,10 @@ minimum t = S.minimum (stream t)
425-- -----------------------------------------------------------------------------
426-- -----------------------------------------------------------------------------
426-- ** Generating and unfolding 'Text's
427-- ** Generating and unfolding 'Text's
427
428
429+replicate :: Int -> Char -> Text
430+replicate n c = unstream (S.replicate n c)
431+{-# INLINE replicate #-}
432+
428-- | /O(n)/, where @n@ is the length of the result. The 'unfoldr'
433-- | /O(n)/, where @n@ is the length of the result. The 'unfoldr'
429-- function is analogous to the List 'L.unfoldr'. 'unfoldr' builds a
434-- function is analogous to the List 'L.unfoldr'. 'unfoldr' builds a
430-- 'Text' from a seed value. The function takes the element and
435-- 'Text' from a seed value. The function takes the element and
Data/Text/Fusion.hs+12−4
@@ -60,6 +60,7 @@ module Data.Text.Fusion
60 , minimum
60 , minimum
61
61
62 -- * Construction
62 -- * Construction
63+ , replicate
63 , unfoldr
64 , unfoldr
64 , unfoldrN
65 , unfoldrN
65
66
@@ -84,10 +85,9 @@ module Data.Text.Fusion
84 , zipWith
85 , zipWith
85 ) where
86 ) where
86
87
87−import Prelude hiding
88+import Prelude (Bool(..), Char, Either(..), Eq(..), Maybe(..), Monad(..),
88− (map, tail, head, foldr, filter, concat, last, init, null, length, foldl,
89+ Num(..), Ord(..), String, ($), (++), (.), (&&), error,
89− foldl1, foldr1, concatMap, any, all, maximum, minimum, take, drop,
90+ fromIntegral, fst, otherwise, snd)
90− takeWhile, dropWhile, elem, zipWith, reverse)
91import Data.Char (ord)
91import Data.Char (ord)
92import Control.Monad (liftM2)
92import Control.Monad (liftM2)
93import Control.Monad.ST (runST, ST)
93import Control.Monad.ST (runST, ST)
@@ -543,6 +543,14 @@ minimum (Stream next0 s0 _len) = loop0_minimum s0
543-- -----------------------------------------------------------------------------
543-- -----------------------------------------------------------------------------
544-- ** Generating and unfolding streams
544-- ** Generating and unfolding streams
545
545
546+replicate :: Int -> Char -> Stream Char
547+replicate n c = Stream next 0 n
548+ where
549+ {-# INLINE next #-}
550+ next i | i >= n = Done
551+ | otherwise = Yield c (i + 1)
552+{-# INLINE [0] replicate #-}
553+
546-- | /O(n)/, where @n@ is the length of the result. The unfoldr function
554-- | /O(n)/, where @n@ is the length of the result. The unfoldr function
547-- is analogous to the List 'unfoldr'. unfoldr builds a stream
555-- is analogous to the List 'unfoldr'. unfoldr builds a stream
548-- from a seed value. The function takes the element and returns
556-- from a seed value. The function takes the element and returns