Skip to content

Add Result.Extra.combineFoldl #60

@miniBill

Description

@miniBill

combineFoldl

combineFoldl :
    (a -> acc -> Result err acc)
    -> acc
    -> List a
    -> Result err acc
combineFoldl f acc list =
    case list of
        [] ->
            Ok acc

        head :: tail ->
            case f head acc of
                Err e ->
                    Err e

                Ok v ->
                    resultFoldl f v tail

Motivating use case

It's common to fold over a list while keeping track of some state. Doing Result.andThen / Result.map is a List.foldl does not short circuit, whereas this function does.

Metadata

Metadata

Assignees

No one assigned

    Labels

    new functionRequest to add a new function to the library

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions