{-# LANGUAGE BangPatterns, MagicHash
#-}
module Data.JSString.Internal.Fusion (
Stream(..)
, Step(..)
, stream
, unstream
, reverseStream
, length
, reverse
, reverseScanr
, mapAccumL
, unfoldrN
, index
, findIndex
, countChar
) where
import Prelude hiding (length, reverse)
import qualified Data.Text.Internal.Fusion as T
import Data.Coerce (coerce)
import Data.JSString.Internal.Type (JSString(..))
import Data.JSString.Internal.Fusion.Types
import qualified Data.JSString.Internal.Fusion.Common as S
default (Int)
stream :: JSString -> Stream Char
stream :: JSString -> Stream Char
stream = (Text -> Stream Char) -> JSString -> Stream Char
forall a b. Coercible a b => a -> b
coerce Text -> Stream Char
T.stream
{-# INLINE [0] stream #-}
reverseStream :: JSString -> Stream Char
reverseStream :: JSString -> Stream Char
reverseStream = (Text -> Stream Char) -> JSString -> Stream Char
forall a b. Coercible a b => a -> b
coerce Text -> Stream Char
T.reverseStream
{-# INLINE [0] reverseStream #-}
unstream :: Stream Char -> JSString
unstream :: Stream Char -> JSString
unstream = (Stream Char -> Text) -> Stream Char -> JSString
forall a b. Coercible a b => a -> b
coerce Stream Char -> Text
T.unstream
{-# INLINE [0] unstream #-}
{-# RULES "STREAM stream/unstream fusion" forall s. stream (unstream s) = s #-}
length :: Stream Char -> Int
length :: Stream Char -> Int
length = Stream Char -> Int
forall a. Integral a => Stream Char -> a
S.lengthI
{-# INLINE[0] length #-}
reverse :: Stream Char -> JSString
reverse :: Stream Char -> JSString
reverse = (Stream Char -> Text) -> Stream Char -> JSString
forall a b. Coercible a b => a -> b
coerce Stream Char -> Text
T.reverse
{-# INLINE [0] reverse #-}
reverseScanr :: (Char -> Char -> Char) -> Char -> Stream Char -> Stream Char
reverseScanr :: (Char -> Char -> Char) -> Char -> Stream Char -> Stream Char
reverseScanr = ((Char -> Char -> Char) -> Char -> Stream Char -> Stream Char)
-> (Char -> Char -> Char) -> Char -> Stream Char -> Stream Char
forall a b. Coercible a b => a -> b
coerce (Char -> Char -> Char) -> Char -> Stream Char -> Stream Char
T.reverseScanr
{-# INLINE reverseScanr #-}
unfoldrN :: Int -> (a -> Maybe (Char,a)) -> a -> Stream Char
unfoldrN :: forall a. Int -> (a -> Maybe (Char, a)) -> a -> Stream Char
unfoldrN Int
n = Int -> (a -> Maybe (Char, a)) -> a -> Stream Char
forall a b.
Integral a =>
a -> (b -> Maybe (Char, b)) -> b -> Stream Char
S.unfoldrNI Int
n
{-# INLINE [0] unfoldrN #-}
index :: Stream Char -> Int -> Char
index :: Stream Char -> Int -> Char
index = Stream Char -> Int -> Char
forall a. (HasCallStack, Integral a) => Stream Char -> a -> Char
S.indexI
{-# INLINE [0] index #-}
findIndex :: (Char -> Bool) -> Stream Char -> Maybe Int
findIndex :: (Char -> Bool) -> Stream Char -> Maybe Int
findIndex = (Char -> Bool) -> Stream Char -> Maybe Int
forall a. Integral a => (Char -> Bool) -> Stream Char -> Maybe a
S.findIndexI
{-# INLINE [0] findIndex #-}
countChar :: Char -> Stream Char -> Int
countChar :: Char -> Stream Char -> Int
countChar = Char -> Stream Char -> Int
forall a. Integral a => Char -> Stream Char -> a
S.countCharI
{-# INLINE [0] countChar #-}
mapAccumL :: (a -> Char -> (a, Char)) -> a -> Stream Char -> (a, JSString)
mapAccumL :: forall a.
(a -> Char -> (a, Char)) -> a -> Stream Char -> (a, JSString)
mapAccumL a -> Char -> (a, Char)
a a
b Stream Char
c = (a, Text) -> (a, JSString)
forall a b. Coercible a b => a -> b
coerce ((a -> Char -> (a, Char)) -> a -> Stream Char -> (a, Text)
forall a. (a -> Char -> (a, Char)) -> a -> Stream Char -> (a, Text)
T.mapAccumL a -> Char -> (a, Char)
a a
b Stream Char
c)
{-# INLINE [0] mapAccumL #-}