-- | /O(n)/ 'splitAt' @n t@ returns a pair whose first element is a

-- prefix of @t@ of length @n@, and whose second is the remainder of

-- the string. It is equivalent to @('take' n t, 'drop' n t)@.

-splitAt :: Int -> Text -> (Text, Text)

+splitAt :: Int64 -> Text -> (Text, Text)

where loop _ Empty = (empty, empty)

loop n t | n <= 0 = (empty, t)

- | n < len = let (ts',ts'') = T.splitAt ~~n~~ t

+ | n < len = let (ts',ts'') = T.splitAt (fromIntegral n) t

in (Chunk ts' Empty, Chunk ts'' Empty)

| otherwise = let (ts',ts'') = loop (n - len) ts

instance Target TL.Text where

+ splitAtT = TL.splitAt . fromIntegral

-- Do two functions give the same answer?

eq :: (Eq a) => (t -> a) -> (t -> a) -> t -> Bool

prop_T_dropWhile p = L.dropWhile p `eqP` (unpackT . T.dropWhile p)

prop_TL_dropWhile p = L.dropWhile p `eqP` (unpackT . S.dropWhile p)

prop_T_splitAt n = L.splitAt n `eqP` (unpack2 . T.splitAt n)

-prop_TL_splitAt n = L.splitAt n `eqP` (unpack2 . TL.splitAt ~~n~~)

+prop_TL_splitAt n = L.splitAt n `eqP` (unpack2 . TL.splitAt (fromIntegral n))

prop_T_span p = L.span p `eqP` (unpack2 . T.span p)

prop_T_break p = L.break p `eqP` (unpack2 . T.break p)

prop_T_group = L.group `eqP` (map unpackT . T.group)