Hoogle Search

Within LTS Haskell 24.6 (ghc-9.10.2)

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

  1. foldl' :: (a -> PosixChar -> a) -> a -> PosixString -> a

    os-string System.OsString.Posix

    foldl' is like foldl, but strict in the accumulator.

  2. foldl1 :: (PosixChar -> PosixChar -> PosixChar) -> PosixString -> PosixChar

    os-string System.OsString.Posix

    foldl1 is a variant of foldl that has no starting value argument, and thus must be applied to non-empty OsStrings. An exception will be thrown in the case of an empty OsString.

  3. foldl1' :: (PosixChar -> PosixChar -> PosixChar) -> PosixString -> PosixChar

    os-string System.OsString.Posix

    foldl1' is like foldl1, but strict in the accumulator. An exception will be thrown in the case of an empty OsString.

  4. foldl' :: (a -> WindowsChar -> a) -> a -> WindowsString -> a

    os-string System.OsString.Windows

    foldl' is like foldl, but strict in the accumulator.

  5. foldl1 :: (WindowsChar -> WindowsChar -> WindowsChar) -> WindowsString -> WindowsChar

    os-string System.OsString.Windows

    foldl1 is a variant of foldl that has no starting value argument, and thus must be applied to non-empty OsStrings. An exception will be thrown in the case of an empty OsString.

  6. foldl1' :: (WindowsChar -> WindowsChar -> WindowsChar) -> WindowsString -> WindowsChar

    os-string System.OsString.Windows

    foldl1' is like foldl1, but strict in the accumulator. An exception will be thrown in the case of an empty OsString.

  7. foldlSC :: Foldable t => (b -> a -> Either b b) -> b -> t a -> b

    relude Relude.Extra.Foldable

    A left-associative fold that's tail-recursive but can still short-circuit. Returning a Left short-circuits and immediately returns the value inside. Returning a Right continues the fold as usual with the value inside.

    >>> foldlSC (\acc x -> if x == 0 then Left 0 else Right $! acc * x) 1 [1..6]
    720
    
    >>> foldlSC (\acc x -> if x == 0 then Left 0 else Right $! acc * x) 1 (0:error "Short-circuiting should keep this from happening")
    0
    

  8. foldl1' :: (a -> a -> a) -> NonEmpty a -> a

    relude Relude.Extra.Foldable1

    Strictly folds non-empty structure with given function f:

    foldl1' f [x0, x1, x2 ...] = f (f x0 x1) x2 ...
    
    >>> foldl1' (++) ([1,2] :| [[3,4], [5,6]])
    [1,2,3,4,5,6]
    

  9. foldl' :: Foldable t => (b -> a -> b) -> b -> t a -> b

    relude Relude.Foldable.Reexport

    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 (e.g. sum). For a general Foldable structure this should be semantically identical to,

    foldl' f z = foldl' f z . toList
    

  10. foldlM :: (Foldable t, Monad m) => (b -> a -> m b) -> b -> t a -> m b

    relude Relude.Foldable.Reexport

    Left-to-right monadic fold over the elements of a structure. Given a structure t with elements (a, b, ..., w, x, y), the result of a fold with an operator function f is equivalent to:

    foldlM f z t = do
    aa <- f z a
    bb <- f aa b
    ...
    xx <- f ww x
    yy <- f xx y
    return yy -- Just @return z@ when the structure is empty
    
    For a Monad m, given two functions f1 :: a -> m b and f2 :: b -> m c, their Kleisli composition (f1 >=> f2) :: a -> m c is defined by:
    (f1 >=> f2) a = f1 a >>= f2
    
    Another way of thinking about foldlM is that it amounts to an application to z of a Kleisli composition:
    foldlM f z t =
    flip f a >=> flip f b >=> ... >=> flip f x >=> flip f y $ z
    
    The monadic effects of foldlM are sequenced from left to right. If at some step the bind operator (>>=) short-circuits (as with, e.g., mzero in a MonadPlus), the evaluated effects will be from an initial segment of the element sequence. If you want to evaluate the monadic effects in right-to-left order, or perhaps be able to short-circuit after processing a tail of the sequence of elements, you'll need to use foldrM instead. If the monadic effects don't short-circuit, the outermost application of f is to the rightmost element y, so that, ignoring effects, the result looks like a left fold:
    ((((z `f` a) `f` b) ... `f` w) `f` x) `f` y
    

    Examples

    Basic usage:
    >>> let f a e = do { print e ; return $ e : a }
    
    >>> foldlM f [] [0..3]
    0
    1
    2
    3
    [3,2,1,0]
    

Page 48 of many | Previous | Next