Wanted to propose a function like SQL's coalesce (a.k.a. nvl):
http://www.postgresql.org/docs/9.2/static/functions-conditional.html#FUNCTIONS-COALESCE-NVL-IFNULL:
"The COALESCE function returns the first of its arguments that is not null."
It would help simplify a typical Ecto.Repo.insert_or_update invocation.
E.g. from Ecto.Repo help:
case MyRepo.get(Post, id) do
nil -> %Post{id: id}
post -> post
end
|> Post.changeset(changes)
|> MyRepo.insert_or_update
More realistically you have a good-size pipeline before the case
setting up the query before running it. So now it looks like this:
from(p in Post)
|> MyRepo.one
|> case do
nil -> %Post{id: id}
post -> post
end
|> Post.changeset(changes)
|> MyRepo.insert_or_update
With coalesce this would become:
from(p in Post)
|> MyRepo.one
|> coalesce(%Post{id: id})
|> Post.changeset(changes)
|> MyRepo.insert_or_update
Thoughts?
Best regards,
Gleb