Hoogle Search

Within LTS Haskell 24.36 (ghc-9.10.3)

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

  1. foldlMap1 :: Foldable1 t => (a -> b) -> (b -> a -> b) -> t a -> b

    base Data.Foldable1

    Left-associative fold of a structure, lazy in the accumulator. This is rarely what you want, but can work well for structures with efficient right-to-left sequencing and an operator that is lazy in its left argument. In case of NonEmpty lists, foldlMap1, when given a function f, a binary operator g, and a list, reduces the list using g from left to right applying f to the leftmost element:

    foldlMap1 f g (x1 :| [x2, ..., xn]) == (...(((f x1) `g` x2) `g`...) `g` xn
    
    Note that to produce the outermost application of the operator the entire input list must be traversed. This means that foldlMap1 will diverge if given an infinite list. If you want an efficient strict left-fold, you probably want to use foldlMap1' instead of foldlMap1. The reason for this is that the latter does not force the inner results (e.g. (f x1) `g` x2 in the above example) before applying them to the operator (e.g. to (`g` x3)). This results in a thunk chain <math> elements long, which then must be evaluated from the outside-in. For a general Foldable1 structure this should be semantically identical to:
    foldlMap1 f g = foldlMap1 f g . toNonEmpty
    

  2. foldlMap1' :: Foldable1 t => (a -> b) -> (b -> a -> b) -> t a -> b

    base Data.Foldable1

    Left-associative fold of a structure but with strict application of the operator. This ensures that each step of the fold is forced to Weak Head Normal Form before being applied, avoiding the collection of thunks that would otherwise occur. This is often what you want to strictly reduce a finite structure to a single strict result. For a general Foldable1 structure this should be semantically identical to:

    foldlMap1' f z = foldlMap1' f z . toNonEmpty
    

  3. foldlMapM1 :: (Foldable1 t, Monad m) => (a -> m b) -> (b -> a -> m b) -> t a -> m b

    base Data.Foldable1

    Map variant of foldlM1.

  4. foldrMap1 :: Foldable1 t => (a -> b) -> (a -> b -> b) -> t a -> b

    base Data.Foldable1

    Right-associative fold of a structure, lazy in the accumulator. In case of NonEmpty lists, foldrMap1, when given a function f, a binary operator g, and a list, reduces the list using g from right to left applying f to the rightmost element:

    foldrMap1 f g (x1 :| [x2, ..., xn1, xn]) == x1 `g` (x2 `g` ... (xn1 `g` (f xn))...)
    
    Note that since the head of the resulting expression is produced by an application of g to the first element of the list, if g is lazy in its right argument, foldrMap1 can produce a terminating expression from an unbounded list. For a general Foldable1 structure this should be semantically identical to:
    foldrMap1 f g = foldrMap1 f g . toNonEmpty
    

  5. foldrMap1' :: Foldable1 t => (a -> b) -> (a -> b -> b) -> t a -> b

    base Data.Foldable1

    foldrMap1' is a variant of foldrMap1 that performs strict reduction from right to left, i.e. starting with the right-most element. The input structure must be finite, otherwise foldrMap1' runs out of space (diverges). If you want a strict right fold in constant space, you need a structure that supports faster than <math> access to the right-most element. This method does not run in constant space for structures such as NonEmpty lists that don't support efficient right-to-left iteration and so require <math> space to perform right-to-left reduction. Use of this method with such a structure is a hint that the chosen structure may be a poor fit for the task at hand. If the order in which the elements are combined is not important, use foldlMap1' instead.

  6. foldrMapM1 :: (Foldable1 t, Monad m) => (a -> m b) -> (a -> b -> m b) -> t a -> m b

    base Data.Foldable1

    Map variant of foldrM1.

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

    base Data.Functor

    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)
    

  8. contramap :: Contravariant f => (a' -> a) -> f a -> f a'

    base Data.Functor.Contravariant

    No documentation available.

  9. fmapDefault :: Traversable t => (a -> b) -> t a -> t b

    base Data.Traversable

    This function may be used as a value for fmap in a Functor instance, provided that traverse is defined. (Using fmapDefault with a Traversable instance defined only by sequenceA will result in infinite recursion.)

    fmapDefault f ≡ runIdentity . traverse (Identity . f)
    

  10. foldMapDefault :: (Traversable t, Monoid m) => (a -> m) -> t a -> m

    base Data.Traversable

    This function may be used as a value for foldMap in a Foldable instance.

    foldMapDefault f ≡ getConst . traverse (Const . f)
    

Page 400 of many | Previous | Next