Aelve Codesearch

grep over package repositories
Please provide a string to search for.
3+ characters are required.
Index updated about a month ago

total matches: 462

ghc-exactprint-0.6.1
1 matches
tests/examples/ghc80/RulePragma.hs
module Data.Text.Internal.Fusion.Common where

{-#
  RULES "STREAM map/map fusion" forall f g s.
     map f (map g s) = map (\x -> f (g x)) s
 #-}


            
ghcjs-base-0.2.0.0
12 matches
Data/JSString/Internal/Fusion/Common.hs
                                            , isSingleton

                                              -- * Transformations
                                            , map
                                            , intercalate
                                            , intersperse

                                              -- ** Case conversion
                                              -- $case

            
Data/JSString/Internal/Fusion/Common.hs
                                              -- ** Scans
                                            , scanl

                                              -- ** Accumulating maps
                                              -- , mapAccumL

                                              -- ** Generation and unfolding
                                            , replicateCharI
                                            , replicateI
                                            , unfoldr

            
Data/JSString/Internal/Fusion/Common.hs
-- ----------------------------------------------------------------------------
-- * Stream transformations

-- | /O(n)/ 'map' @f @xs is the Stream Char obtained by applying @f@
-- to each element of @xs@.
map :: (Char -> Char) -> Stream Char -> Stream Char
map f (Stream next0 s0) = Stream next s0
    where
      next !s = case next0 s of
                  Done       -> Done
                  Skip s'    -> Skip s'
                  Yield x s' -> Yield (f x) s'

            
Data/JSString/Internal/Fusion/Common.hs
                  Done       -> Done
                  Skip s'    -> Skip s'
                  Yield x s' -> Yield (f x) s'
{-# INLINE [0] map #-}

{-#
  RULES "STREAM map/map fusion" forall f g s.
     map f (map g s) = map (\x -> f (g x)) s
 #-}

data I s = I1 !s
         | I2 !s {-# UNPACK #-} !Char
         | I3 !s

            
Data/JSString/Internal/Fusion/Common.hs

-- $case
--
-- With Unicode text, it is incorrect to use combinators like @map
-- toUpper@ to case convert each character of a string individually.
-- Instead, use the whole-string case conversion functions from this
-- module.  For correctness in different writing systems, these
-- functions may map one input character to two or three output
-- characters.

caseConvert :: (forall s. Char -> s -> Step (CC s) Char)
            -> Stream Char -> Stream Char
caseConvert remap (Stream next0 s0) = Stream next (CC s0 '\0' '\0')

            
Data/JSString/Internal/Fusion/Common.hs

caseConvert :: (forall s. Char -> s -> Step (CC s) Char)
            -> Stream Char -> Stream Char
caseConvert remap (Stream next0 s0) = Stream next (CC s0 '\0' '\0')
  where
    next (CC s '\0' _) =
        case next0 s of
          Done       -> Done
          Skip s'    -> Skip (CC s' '\0' '\0')

            
Data/JSString/Internal/Fusion/Common.hs
        case next0 s of
          Done       -> Done
          Skip s'    -> Skip (CC s' '\0' '\0')
          Yield c s' -> remap c s'
    next (CC s a b)  =  Yield a (CC s b '\0')

-- | /O(n)/ Convert a string to folded case.  This function is mainly
-- useful for performing caseless (or case insensitive) string
-- comparisons.

            
Data/JSString/Internal/Fusion/Common.hs

-- | /O(n)/ Convert a string to upper case, using simple case
-- conversion.  The result string may be longer than the input string.
-- For instance, the German eszett (U+00DF) maps to the two-letter
-- sequence SS.
toUpper :: Stream Char -> Stream Char
toUpper = caseConvert upperMapping
{-# INLINE [0] toUpper #-}


            
Data/JSString/Internal/Fusion/Common.hs
-- | /O(n)/ Convert a string to lower case, using simple case
-- conversion.  The result string may be longer than the input string.
-- For instance, the Latin capital letter I with dot above (U+0130)
-- maps to the sequence Latin small letter i (U+0069) followed by
-- combining dot above (U+0307).
toLower :: Stream Char -> Stream Char
toLower = caseConvert lowerMapping
{-# INLINE [0] toLower #-}


            
Data/JSString/Internal/Fusion/Common.hs
{-# INLINE [0] scanl #-}

-- -----------------------------------------------------------------------------
-- ** Accumulating maps

{-
-- | /O(n)/ Like a combination of 'map' and 'foldl'. Applies a
-- function to each element of a stream, passing an accumulating
-- parameter from left to right, and returns a final stream.
--
-- /Note/: Unlike the version over lists, this function does not
-- return a final value for the accumulator, because the nature of

            
Data/JSString/Internal/Fusion/Common.hs
-- /Note/: Unlike the version over lists, this function does not
-- return a final value for the accumulator, because the nature of
-- streams precludes it.
mapAccumL :: (a -> b -> (a,b)) -> a -> Stream b -> Stream b
mapAccumL f z0 (Stream next0 s0 len) = Stream next (s0 :*: z0) len -- HINT depends on f
  where
    {-# INLINE next #-}
    next (s :*: z) = case next0 s of
                       Yield x s' -> let (z',y) = f z x
                                     in Yield y (s' :*: z')

            
Data/JSString/Internal/Fusion/Common.hs
                                     in Yield y (s' :*: z')
                       Skip s'    -> Skip (s' :*: z)
                       Done       -> Done
{-# INLINE [0] mapAccumL #-}
-}

-- -----------------------------------------------------------------------------
-- ** Generating and unfolding streams


            
jsaddle-0.9.6.0
13 matches
src-ghc/Data/JSString/Internal/Fusion/Common.hs
                                            , isSingleton

                                              -- * Transformations
                                            , map
                                            , intercalate
                                            , intersperse

                                              -- ** Case conversion
                                              -- $case

            
src-ghc/Data/JSString/Internal/Fusion/Common.hs
                                              -- ** Scans
                                            , scanl

                                              -- ** Accumulating maps
                                              -- , mapAccumL

                                              -- ** Generation and unfolding
                                            , replicateCharI
                                            , replicateI
                                            , unfoldr

            
src-ghc/Data/JSString.hs
                     , compareLength

                       -- * Transformations
                     , map
                     , intercalate
                     , intersperse
                     , transpose
                     , reverse
                     , replace

            
src-ghc/Data/JSString.hs
                     , scanr
                     , scanr1

                       -- ** Accumulating maps
                     , mapAccumL
                     , mapAccumR

                       -- ** Generation and unfolding
                     , replicate
                     , unfoldr
                     , unfoldrN

            
src-ghc/Data/JSString.hs

{-# RULES
"JSSTRING pack -> fused" [~1] forall x.
    pack x = unstream (S.map safe (S.streamList x))
"JSSTRING pack -> unfused" [1] forall x.
    unstream (S.map safe (S.streamList x)) = pack x
  #-}

-- | /O(n)/ Convert a 'JSString' into a 'String'.  Subject to fusion.
unpack :: JSString -> String
unpack = S.unstreamList . stream

            
src-ghc/Data/JSString.hs
{-# NOINLINE unpackCString# #-}

{-# RULES "JSSTRING literal" forall a.
    unstream (S.map safe (S.streamList (GHC.unpackCString# a)))
      = unpackCString# a #-}

{-# RULES "JSSTRING literal UTF8" forall a.
    unstream (S.map safe (S.streamList (GHC.unpackCStringUtf8# a)))
      = unpackCString# a #-}

{-# RULES "JSSTRING empty literal"
    unstream (S.map safe (S.streamList []))
      = empty_ #-}

{-# RULES "JSSTRING singleton literal" forall a.
    unstream (S.map safe (S.streamList [a]))
      = singleton a #-}


-- | /O(1)/ Convert a character into a 'JSString'.  Subject to fusion.
-- Performs replacement on invalid scalar values.

            
src-ghc/Data/JSString.hs

-- -----------------------------------------------------------------------------
-- * Transformations
-- | /O(n)/ 'map' @f@ @t@ is the 'JSString' obtained by applying @f@ to
-- each element of @t@.  Subject to fusion.  Performs replacement on
-- invalid scalar values.
map :: (Char -> Char) -> JSString -> JSString
map = coerce T.map
{-# INLINE [1] map #-}

-- | /O(n)/ The 'intercalate' function takes a 'JSString' and a list of
-- 'JSString's and concatenates the list after interspersing the first
-- argument between each element of the list.
intercalate :: JSString -> [JSString] -> JSString

            
src-ghc/Data/JSString.hs
-- $case
--
-- When case converting 'JSString' values, do not use combinators like
-- @map toUpper@ to case convert each character of a string
-- individually, as this gives incorrect results according to the
-- rules of some writing systems.  The whole-string case conversion
-- functions from this module, such as @toUpper@, obey the correct
-- case conversion rules.  As a result, these functions may map one
-- input character to two or three output characters. For examples,
-- see the documentation of each function.
--
-- /Note/: In some languages, case conversion is a locale- and
-- context-dependent operation. The case conversion functions in this

            
src-ghc/Data/JSString.hs
-- context-dependent operation. The case conversion functions in this
-- module are /not/ locale sensitive. Programs that require locale
-- sensitivity should use appropriate versions of the
-- <http://hackage.haskell.org/package/text-icu-0.6.3.7/docs/Data-Text-ICU.html#g:4 case mapping functions from the text-icu package >.

-- | /O(n)/ Convert a string to folded case.  Subject to fusion.
--
-- This function is mainly useful for performing caseless (also known
-- as case insensitive) string comparisons.

            
src-ghc/Data/JSString.hs
--
-- The result string may be longer than the input string.  For
-- instance, \"&#x130;\" (Latin capital letter I with dot above,
-- U+0130) maps to the sequence \"i\" (Latin small letter i, U+0069)
-- followed by \" &#x307;\" (combining dot above, U+0307).
toLower :: JSString -> JSString
toLower = coerce T.toLower
{-# INLINE [1] toLower #-}


            
src-ghc/Data/JSString.hs
-- conversion.  Subject to fusion.
--
-- The result string may be longer than the input string.  For
-- instance, the German \"&#xdf;\" (eszett, U+00DF) maps to the
-- two-letter sequence \"SS\".
toUpper :: JSString -> JSString
toUpper = coerce T.toUpper
{-# INLINE [1] toUpper #-}


            
src-ghc/Data/JSString.hs
scanr1 = coerce T.scanr1
{-# INLINE scanr1 #-}

-- | /O(n)/ Like a combination of 'map' and 'foldl''. Applies a
-- function to each element of a 'JSString', passing an accumulating
-- parameter from left to right, and returns a final 'JSString'.  Performs
-- replacement on invalid scalar values.
mapAccumL :: (a -> Char -> (a,Char)) -> a -> JSString -> (a, JSString)
mapAccumL f = coerce (T.mapAccumL f)
{-# INLINE mapAccumL #-}

-- | The 'mapAccumR' function behaves like a combination of 'map' and
-- a strict 'foldr'; it applies a function to each element of a
-- 'JSString', passing an accumulating parameter from right to left, and
-- returning a final value of this accumulator together with the new
-- 'JSString'.
-- Performs replacement on invalid scalar values.

            
src-ghc/Data/JSString.hs
-- returning a final value of this accumulator together with the new
-- 'JSString'.
-- Performs replacement on invalid scalar values.
mapAccumR :: (a -> Char -> (a,Char)) -> a -> JSString -> (a, JSString)
mapAccumR f = coerce (T.mapAccumR f)
{-# INLINE mapAccumR #-}

-- -----------------------------------------------------------------------------
-- ** Generating and unfolding 'JSString's

-- | /O(n*m)/ 'replicate' @n@ @t@ is a 'JSString' consisting of the input

            
text-manipulate-0.2.0.1
4 matches
src/Data/Text/Manipulate/Internal/Fusion.hs
{-# INLINE [0] dropWord #-}

toTitle :: Stream Char -> Stream Char
toTitle = mapHead toUpper . transformWith (yield ' ') upper lower . tokenise
{-# INLINE [0] toTitle #-}

toCamel :: Stream Char -> Stream Char
toCamel = mapHead toLower . transformWith skip' upper lower . tokenise
{-# INLINE [0] toCamel #-}

toPascal :: Stream Char -> Stream Char
toPascal = mapHead toUpper . transformWith skip' upper lower . tokenise
{-# INLINE [0] toPascal #-}

toSnake :: Stream Char -> Stream Char
toSnake = transform (yield '_') lower . tokenise
{-# INLINE [0] toSnake #-}

            
src/Data/Text/Manipulate/Internal/Fusion.hs
{-# INLINE [0] toSpinal #-}

toTrain :: Stream Char -> Stream Char
toTrain = mapHead toUpper . transformWith (yield '-') upper lower . tokenise
{-# INLINE [0] toTrain #-}

strict :: (Stream Char -> Stream Char) -> Text -> Text
strict f t = Fusion.unstream (f (Fusion.stream t))
{-# INLINE [0] strict #-}

            
src/Data/Text/Manipulate/Internal/Fusion.hs
--
-- /See:/ 'transformWith'
transform :: (forall s. s -> Step (CC s) Char)         -- ^ Boundary action.
          -> (forall s. Char -> s -> Step (CC s) Char) -- ^ Character mapping.
          -> Stream Token                              -- ^ Input stream.
          -> Stream Char
transform s m = transformWith s m m
{-# INLINE [0] transform #-}


            
src/Data/Text/Manipulate/Internal/Fusion.hs
{-# INLINE [0] transform #-}

-- | Step across word boundaries using a custom action, and transform
-- subsequent characters after the word boundary is encountered with a mapping
-- depending on case.
transformWith :: (forall s. s -> Step (CC s) Char)         -- ^ Boundary action.
              -> (forall s. Char -> s -> Step (CC s) Char) -- ^ Boundary mapping.
              -> (forall s. Char -> s -> Step (CC s) Char) -- ^ Subsequent character mapping.
              -> Stream Token                              -- ^ Input stream.
              -> Stream Char
transformWith md mu mc (Stream next0 s0 len) =
    -- HINT: len incorrect when the boundary replacement yields a char.
    Stream next (CC (False :*: False :*: s0) '\0' '\0') len