Elm Exactly
Results / elm-core /

MaybeAndThenTest

elm-0.19.1 passelm-0.19.2 passelm-0.19.3 passlamdera-1.5.0 pass
`Maybe.andThen` applies a `Maybe`-returning function to a `Just` value and passes `Nothing` through.

`half` returns `Just (x // 2)` for an even `x` and `Nothing` for an odd one. The
test logs `andThen half` on `Just 42` (giving `Just 21`), on `Just 41` (the
function returns `Nothing`) and on `Nothing` (the function is never applied).

Results

elm-0.19.1

passran in 89 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets.
andThen1: Just 21
andThen2: Nothing
andThen3: Nothing

elm-0.19.2

passran in 81 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets.
andThen1: Just 21
andThen2: Nothing
andThen3: Nothing

elm-0.19.3

passran in 52 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets.
andThen1: Just 21
andThen2: Nothing
andThen3: Nothing

lamdera-1.5.0

passran in 84 ms
Output
andThen1: Just 21
andThen2: Nothing
andThen3: Nothing

Discussions

Discuss this test·Search the discussions on GitHub

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

Source

The -- CHECK: lines give the expected output.

module MaybeAndThenTest exposing (main)
{-| `Maybe.andThen` applies a `Maybe`-returning function to a `Just` value and passes `Nothing` through.
`half` returns `Just (x // 2)` for an even `x` and `Nothing` for an odd one. The
test logs `andThen half` on `Just 42` (giving `Just 21`), on `Just 41` (the
function returns `Nothing`) and on `Nothing` (the function is never applied).
-}
-- CHECK: andThen1: Just 21
-- CHECK: andThen2: Nothing
-- CHECK: andThen3: Nothing
import Html exposing (text)
half x =
if modBy 2 x == 0 then
Just (x // 2)
else
Nothing
main =
let
_ = Debug.log "andThen1" (Maybe.andThen half (Just 42))
_ = Debug.log "andThen2" (Maybe.andThen half (Just 41))
_ = Debug.log "andThen3" (Maybe.andThen half Nothing)
in
text "done"