Control structure `with else` problem

In your first example,

  • When App.Repo.get(App.Room, 1) returns nil it will still bind nil to room.
  • Then test_fn("good") will return true so that will also pass.
  • Lastly. it will execute IO.inspect(room) and since room == nil you see nil.

From that explanation I think you can work out the second example. You might find some value in with room when not is_nil(room) <- App.Repo.get(App.Room, 1).