-- -----------------------------------------------------------------------------

--- | /O(n)/ 'map' @f @t@ is the 'Text' obtained by applying @f@ to

+-- | /O(n)/ 'map' @f@ @t@ is the 'Text' obtained by applying @f@ to

-- each element of @t@. Subject to array fusion.

map :: (Char -> Char) -> Text -> Text

map f t = unstream (S.map f (stream t))

-- | /O(n)/ 'dropAfter' @p@ @t@ returns the prefix remaining after

-- dropping characters that fail the predicate @p@ from the end of

-- @t@. This function is subject to array fusion.

+-- For example, to drop trailing white space:

dropAfter :: (Char -> Bool) -> Text -> Text

dropAfter p t@(Text arr off len) = loop (len-1) len

where loop !i !l | l <= 0 = empty

S.length (stream t) = length t

--- | /O(n)/ 'map' @f @t@ is the 'Text' obtained by applying @f@ to

+-- | /O(n)/ 'map' @f@ @t@ is the 'Text' obtained by applying @f@ to

-- each element of @t@. Subject to array fusion.

map :: (Char -> Char) -> Text -> Text

map f t = unstream (S.map f (stream t))