Skip to content

Instantly share code, notes, and snippets.

@chrisza4
Created November 18, 2019 16:38
Show Gist options
  • Select an option

  • Save chrisza4/2278c8329ea349a29b8a265ed86dad0c to your computer and use it in GitHub Desktop.

Select an option

Save chrisza4/2278c8329ea349a29b8a265ed86dad0c to your computer and use it in GitHub Desktop.
So many nil check
# Assuming get(id) is database hit, so we don't want to hit database for everything up-front
def some_func(id1, id2, id3) do
if EntityA.get(id1) == nil do
{:error, :not_found}
else
if EntityB.get(id2) == nil do
{:error, :not_found}
else
if EntityC.get(id3) == nil do
{:error, :not_found}
else
# Start do something
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment