Elm Exactly
Results / elm-core /

MaybeWithDefaultTest

elm-0.19.1 passelm-0.19.2 passelm-0.19.3 passlamdera-1.5.0 pass
`Maybe.withDefault` returns the wrapped value of a `Just` and the default for `Nothing`.

With default `0`, `Just 42` gives `42` and `Nothing` gives `0`.

Results

elm-0.19.1

passran in 43 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets.
withDefault1: 42
withDefault2: 0

elm-0.19.2

passran in 45 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets.
withDefault1: 42
withDefault2: 0

elm-0.19.3

passran in 73 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets.
withDefault1: 42
withDefault2: 0

lamdera-1.5.0

passran in 42 ms
Output
withDefault1: 42
withDefault2: 0

Discussions

Discuss this test·Search the discussions on GitHub

Discussions are on GitHub; one about this test has [t:elm-core/MaybeWithDefaultTest] in its title.

Source

The -- CHECK: lines give the expected output.

module MaybeWithDefaultTest exposing (main)
{-| `Maybe.withDefault` returns the wrapped value of a `Just` and the default for `Nothing`.
With default `0`, `Just 42` gives `42` and `Nothing` gives `0`.
-}
-- CHECK: withDefault1: 42
-- CHECK: withDefault2: 0
import Html exposing (text)
main =
let
_ = Debug.log "withDefault1" (Maybe.withDefault 0 (Just 42))
_ = Debug.log "withDefault2" (Maybe.withDefault 0 Nothing)
in
text "done"