tam-carre/and-collect/1.0.1

NOTE: the latest version is 1.0.2

Unavailable. Nobody can download this version any more, with elm or with the Lamdera compiler: github.com/tam-carre/and-collect is gone (deleted or private); Software Heritage not asked yet (this run's --swh-calls were used up); no fork with tag 1.0.1 found (1 same-name repos checked); no cached copy. Use another version.

Details

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)