Hoogle Search

Within LTS Haskell 24.34 (ghc-9.10.3)

Note that Stackage only displays results for the latest LTS and Nightly snapshot. Learn more.

  1. fmap :: Functor f => (a -> b) -> f a -> f b

    base GHC.Base

    fmap is used to apply a function of type (a -> b) to a value of type f a, where f is a functor, to produce a value of type f b. Note that for any type constructor with more than one parameter (e.g., Either), only the last type parameter can be modified with fmap (e.g., b in `Either a b`). Some type constructors with two parameters or more have a Bifunctor instance that allows both the last and the penultimate parameters to be mapped over.

    Examples

    Convert from a Maybe Int to a Maybe String using show:
    >>> fmap show Nothing
    Nothing
    
    >>> fmap show (Just 3)
    Just "3"
    
    Convert from an Either Int Int to an Either Int String using show:
    >>> fmap show (Left 17)
    Left 17
    
    >>> fmap show (Right 17)
    Right "17"
    
    Double each element of a list:
    >>> fmap (*2) [1,2,3]
    [2,4,6]
    
    Apply even to the second element of a pair:
    >>> fmap even (2,2)
    (2,True)
    
    It may seem surprising that the function is only applied to the last element of the tuple compared to the list example above which applies it to every element in the list. To understand, remember that tuples are type constructors with multiple type parameters: a tuple of 3 elements (a,b,c) can also be written (,,) a b c and its Functor instance is defined for Functor ((,,) a b) (i.e., only the third parameter is free to be mapped over with fmap). It explains why fmap can be used with tuples containing values of different types as in the following example:
    >>> fmap even ("hello", 1.0, 4)
    ("hello",1.0,True)
    

  2. concatMap :: (a -> [b]) -> [a] -> [b]

    base GHC.List

    Map a function returning a list over a list and concatenate the results. concatMap can be seen as the composition of concat and map.

    concatMap f xs == (concat . map f) xs
    

    Examples

    >>> concatMap (\i -> [-i,i]) []
    []
    
    >>> concatMap (\i -> [-i, i]) [1, 2, 3]
    [-1,1,-2,2,-3,3]
    
    >>> concatMap ('replicate' 3) [0, 2, 4]
    [0,0,0,2,2,2,4,4,4]
    

  3. concatMap :: (Word8 -> ByteString) -> ByteString -> ByteString

    bytestring Data.ByteString

    Map a function over a ByteString and concatenate the results

  4. primMapByteStringBounded :: BoundedPrim Word8 -> StrictByteString -> Builder

    bytestring Data.ByteString.Builder.Prim

    Create a Builder that encodes each Word8 of a StrictByteString using a BoundedPrim. For example, we can write a Builder that filters a StrictByteString as follows.

    import qualified Data.ByteString.Builder.Prim as P
    
    filterBS p = P.condB p (P.liftFixedToBounded P.word8) P.emptyB
    

  5. primMapByteStringFixed :: FixedPrim Word8 -> StrictByteString -> Builder

    bytestring Data.ByteString.Builder.Prim

    Heavy inlining. Encode all bytes of a StrictByteString from left-to-right with a FixedPrim. This function is quite versatile. For example, we can use it to construct a Builder that maps every byte before copying it to the buffer to be filled.

    mapToBuilder :: (Word8 -> Word8) -> S.StrictByteString -> Builder
    mapToBuilder f = primMapByteStringFixed (contramapF f word8)
    
    We can also use it to hex-encode a StrictByteString as shown by the byteStringHex example above.

  6. primMapLazyByteStringBounded :: BoundedPrim Word8 -> LazyByteString -> Builder

    bytestring Data.ByteString.Builder.Prim

    Chunk-wise application of primMapByteStringBounded.

  7. primMapLazyByteStringFixed :: FixedPrim Word8 -> LazyByteString -> Builder

    bytestring Data.ByteString.Builder.Prim

    Heavy inlining. Encode all bytes of a LazyByteString from left-to-right with a FixedPrim.

  8. primMapListBounded :: BoundedPrim a -> [a] -> Builder

    bytestring Data.ByteString.Builder.Prim

    Create a Builder that encodes a list of values consecutively using a BoundedPrim for each element. This function is more efficient than

    mconcat . map (primBounded w)
    
    or
    foldMap (primBounded w)
    
    because it moves several variables out of the inner loop.

  9. primMapListFixed :: FixedPrim a -> [a] -> Builder

    bytestring Data.ByteString.Builder.Prim

    Encode a list of values from left-to-right with a FixedPrim.

  10. contramapB :: (b -> a) -> BoundedPrim a -> BoundedPrim b

    bytestring Data.ByteString.Builder.Prim.Internal

    Change a BoundedPrim such that it first applies a function to the value to be encoded. Note that BoundedPrims are Contravariant http://hackage.haskell.org/package/contravariant. Hence, the following laws hold.

    contramapB id = id
    contramapB f . contramapB g = contramapB (g . f)
    

Page 401 of many | Previous | Next