replace `if ... then ... else return ()` by `when`