tam-carre/and-collect/1.0.0

NOTE: the latest version is 1.0.2

Rerouted (fork, verified). The original repository is gone. This copy comes from a fork that still has the tag. The Lamdera package server serves a copy recovered from https://github.com/mtamc/and-collect (a fork).

What we checked: Rebuilt with git archive from commit 08b6188aba00 of https://github.com/mtamc/and-collect (a fork) (zip prefix tam-carre-and-collect-08b6188/, America/Los_Angeles times): the zip is byte-identical to the one package.elm-lang.org recorded, SHA-1 fa7a963fb3e8a9eb034c45aae80eb5ed421fc690.

The Lamdera compiler uses this copy and prints a one-line notice saying so. elm itself fails to download this version.

Details · package.elm-lang.org's zip: https://github.com/tam-carre/and-collect/zipball/1.0.0/

Result.AndCollect

andCollect : (a -> Result e b) -> Result e a -> Result e ( a, b )

Combinator for interdependent Result values. Note the type signature similarities with Result.andThen:

andThen : (a -> Result e b) -> Result e a -> Result e b


andCollect : (a -> Result e b) -> Result e a -> Result e ( a, b )

Intended usage is turning interdependent Result values such as this...

computeAnswer : Result error Int
computeAnswer =
    getA
        |> Result.andThen
            (\a ->
                getB a
                    |> Result.andThen
                        (\b ->
                            getC a b
                                |> Result.andThen
                                    (\c ->
                                        solve a b c
                                    )
                        )
            )

... into this:

import Result.AndCollect as Result


computeAnswer : Result error Int
computeAnswer =
    getA
        |> Result.andCollect getB
        |> Result.andCollect (\( a, b ) -> getC a b)
        |> Result.andThen (\( ( a, b ), c ) -> solve a b c)