Skip to content

Instantly share code, notes, and snippets.

@TobiG77
Last active December 22, 2015 01:31
Show Gist options
  • Save TobiG77/c2fa52b879c69f8747ee to your computer and use it in GitHub Desktop.
Save TobiG77/c2fa52b879c69f8747ee to your computer and use it in GitHub Desktop.
functional vs objective thinking and elixir data structures are immutable
doc = %{id: "Foo"}
#wrong
defmodule FooBar do
def valid_version(doc) do
if (is_integer(doc.version)), do: doc, else: doc.version = 1
end
end
# correct
defmodule FooBar do
def valid_version(doc) do
if (is_integer(doc.version)), do: doc, else Map.put(doc, :version, 1)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment