Last active
December 22, 2015 01:31
-
-
Save TobiG77/c2fa52b879c69f8747ee to your computer and use it in GitHub Desktop.
functional vs objective thinking and elixir data structures are immutable
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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