lue-bird/elm-morph/3.0.0

NOTE: the latest version is 3.0.1

Result.Morph

MorphIndependently
( Result narrowError narrowSuccess
-> Result (ErrorWithDeadEnd narrowError) narrowSuccess
)
(broadSuccess -> Result broadSuccess_ broadSuccess)

Ok success succeeds with the success, Err error fails with the error.

import Morph
import Char.Morph


Ok 'Y'
    |> Morph.toNarrow
        (Char.Morph.only 'Y'
            |> Morph.over Result.Morph.toOk
        )
--> Ok ()


Err [ "Hiyo", "!" ]
    |> Morph.toNarrow Result.Morph.toOk
--> Err (Morph.DeadEnd [ "Hiyo", "!" ])

If your error type is not a String, you will need |> Morph.errorMap (Morph.deadEndMap ..your error to String..) to make dead end types unify.

MorphIndependently
(Result narrowError narrowSuccess_ -> Result Error narrowError)
(broadError -> Result broadError broadSuccess_)

Err error succeeds with the error, Ok fails.

import Morph
import Char.Morph


Err 'Y'
    |> Morph.toNarrow
        (Char.Morph.only 'Y'
            |> Morph.over Result.Morph.toErr
        )
--> Ok ()


Ok [ "Bye", "!" ]
    |> Morph.toNarrow Result.Morph.toErr
--> Err (Morph.DeadEnd "ok")