In a phoenix app, when a user submit a specific form, lat and lng are calculated from address.
The lat and lng can be in changeset.data if no changes are made and in changeset.changes if changes are submit.
I perform other stuff on lat and lng on the changeset but I need to know where the coordinates are. What I'm trying to do is:
cond do
# Always use new coordinates if possible
%{lat: lat, lng: lng} = changeset.changes ->
do_something(lat, lng)
%{lat: lat, lng: lng} = changeset.data ->
do_something(lat, lng)
true ->
do_nothing_and_return_the_changeset_as_is
end
Of course this is not working because it's not returning true or false on pattern not matching.
** (MatchError) no match of right hand side value: %{lat: any_value}
I actually made a long not looking good if else if .... statement to achieved this.
Is there a better elixir way of doing this?