on master help sign in
Implement cons
9dd93d8Bryan O'Sullivan
Data/Text/Lazy.hs+12−1
@@ -40,7 +40,7 @@ module Data.Text.Lazy
40 , empty
40 , empty
41
41
42 -- * Basic interface
42 -- * Basic interface
43− -- , cons
43+ , cons
44 -- , snoc
44 -- , snoc
45 , append
45 , append
46 -- , uncons
46 -- , uncons
@@ -194,6 +194,17 @@ singleton c = Chunk (T.singleton c) Empty
194 unstream (S.singleton c) = singleton c
194 unstream (S.singleton c) = singleton c
195 #-}
195 #-}
196
196
197+cons :: Char -> Text -> Text
198+cons c t = Chunk (T.singleton c) t
199+{-# INLINE [1] cons #-}
200+
201+{-# RULES
202+"LAZY TEXT cons -> fused" [~1] forall c t.
203+ cons c t = unstream (S.cons c (stream t))
204+"LAZY TEXT cons -> unfused" [1] forall c t.
205+ unstream (S.cons c (stream t)) = cons c t
206+ #-}
207+
197-- | /O(n\/c)/ Append two 'Text's
208-- | /O(n\/c)/ Append two 'Text's
198append :: Text -> Text -> Text
209append :: Text -> Text -> Text
199append xs ys = foldrChunks Chunk ys xs
210append xs ys = foldrChunks Chunk ys xs