{"action":"created","comment":{"url":"https://api.github.com/repos/dockyard/reefpoints/pulls/comments/51435787","id":51435787,"diff_hunk":"@@ -0,0 +1,91 @@\n+---\n+layout: post\n+title: \"Elixir Best Practices - Deeply Nested Maps\"\n+author: 'Brian Cardarella'\n+twitter: 'bcardarella'\n+github: bcardarella\n+published: true\n+tags: elixir\n+---\n+\n+When writing Elixir apps you'll typically find yourself building up\n+state in a [map][map]. For example, in Phoenix we have the `conn` map.\n+Typically these maps contain deep nesting. Updating anything deeply\n+nested means you have to write some like:\n+\n+```elixir\n+my_map = %{\n+  foo: %{\n+    bar: %{\n+      baz: \"my value\"\n+    }\n+  }\n+}\n+\n+new_bar_map =\n+  my_map\n+  |> Map.get(:foo)\n+  |> Map.get(:bar)\n+  |> Map.put(:baz, \"new value\")\n+\n+new_foo_map =\n+  my_map\n+  |> Map.get(:foo)\n+  |> Map.put(:bar, new_bar_map)\n+\n+Map.put(my_map, :foo, new_foo_map)\n+```\n+\n+That's pretty complex for a simple nested key update!\n+\n+Because of the immutable nature of Elixir, whenever we simply cannot\n+update inplace. You can clean this up a bit by using\n+[`Map.merge/2`][merge]:\n+\n+```elixir\n+# [TODO] merge example","path":"source/posts/2016-02-02-elixir-best-practices-deeply-nested-maps.md","position":46,"original_position":46,"commit_id":"7a916bcbcfac55c056ce92f8751d1a04e362f055","original_commit_id":"cc7850e65ba95d17d7c67e60065c48c166859664","user":{"login":"courajs","id":1588273,"avatar_url":"https://avatars.githubusercontent.com/u/1588273?v=3","gravatar_id":"","url":"https://api.github.com/users/courajs","html_url":"https://github.com/courajs","followers_url":"https://api.github.com/users/courajs/followers","following_url":"https://api.github.com/users/courajs/following{/other_user}","gists_url":"https://api.github.com/users/courajs/gists{/gist_id}","starred_url":"https://api.github.com/users/courajs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/courajs/subscriptions","organizations_url":"https://api.github.com/users/courajs/orgs","repos_url":"https://api.github.com/users/courajs/repos","events_url":"https://api.github.com/users/courajs/events{/privacy}","received_events_url":"https://api.github.com/users/courajs/received_events","type":"User","site_admin":false},"body":"To-done this before merge","created_at":"2016-02-01T15:57:47Z","updated_at":"2016-02-01T15:57:47Z","html_url":"https://github.com/dockyard/reefpoints/pull/444#discussion_r51435787","pull_request_url":"https://api.github.com/repos/dockyard/reefpoints/pulls/444","_links":{"self":{"href":"https://api.github.com/repos/dockyard/reefpoints/pulls/comments/51435787"},"html":{"href":"https://github.com/dockyard/reefpoints/pull/444#discussion_r51435787"},"pull_request":{"href":"https://api.github.com/repos/dockyard/reefpoints/pulls/444"}}},"pull_request":{"url":"https://api.github.com/repos/dockyard/reefpoints/pulls/444","id":56442063,"html_url":"https://github.com/dockyard/reefpoints/pull/444","diff_url":"https://github.com/dockyard/reefpoints/pull/444.diff","patch_url":"https://github.com/dockyard/reefpoints/pull/444.patch","issue_url":"https://api.github.com/repos/dockyard/reefpoints/issues/444","number":444,"state":"open","locked":false,"title":"Elixir Best Practice - Deeply Nested Maps","user":{"login":"bcardarella","id":18524,"avatar_url":"https://avatars.githubusercontent.com/u/18524?v=3","gravatar_id":"","url":"https://api.github.com/users/bcardarella","html_url":"https://github.com/bcardarella","followers_url":"https://api.github.com/users/bcardarella/followers","following_url":"https://api.github.com/users/bcardarella/following{/other_user}","gists_url":"https://api.github.com/users/bcardarella/gists{/gist_id}","starred_url":"https://api.github.com/users/bcardarella/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bcardarella/subscriptions","organizations_url":"https://api.github.com/users/bcardarella/orgs","repos_url":"https://api.github.com/users/bcardarella/repos","events_url":"https://api.github.com/users/bcardarella/events{/privacy}","received_events_url":"https://api.github.com/users/bcardarella/received_events","type":"User","site_admin":false},"body":"To be merged in by Jan 29th for publication on February 2nd","created_at":"2016-01-19T09:45:40Z","updated_at":"2016-02-01T15:57:47Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e50e85308e17f0364562b5c0f310c647371e2031","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/dockyard/reefpoints/pulls/444/commits","review_comments_url":"https://api.github.com/repos/dockyard/reefpoints/pulls/444/comments","review_comment_url":"https://api.github.com/repos/dockyard/reefpoints/pulls/comments{/number}","comments_url":"https://api.github.com/repos/dockyard/reefpoints/issues/444/comments","statuses_url":"https://api.github.com/repos/dockyard/reefpoints/statuses/7a916bcbcfac55c056ce92f8751d1a04e362f055","head":{"label":"dockyard:bc-elixir-best-practice-deeply-nested-maps","ref":"bc-elixir-best-practice-deeply-nested-maps","sha":"7a916bcbcfac55c056ce92f8751d1a04e362f055","user":{"login":"dockyard","id":873981,"avatar_url":"https://avatars.githubusercontent.com/u/873981?v=3","gravatar_id":"","url":"https://api.github.com/users/dockyard","html_url":"https://github.com/dockyard","followers_url":"https://api.github.com/users/dockyard/followers","following_url":"https://api.github.com/users/dockyard/following{/other_user}","gists_url":"https://api.github.com/users/dockyard/gists{/gist_id}","starred_url":"https://api.github.com/users/dockyard/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dockyard/subscriptions","organizations_url":"https://api.github.com/users/dockyard/orgs","repos_url":"https://api.github.com/users/dockyard/repos","events_url":"https://api.github.com/users/dockyard/events{/privacy}","received_events_url":"https://api.github.com/users/dockyard/received_events","type":"Organization","site_admin":false},"repo":{"id":2262874,"name":"reefpoints","full_name":"dockyard/reefpoints","owner":{"login":"dockyard","id":873981,"avatar_url":"https://avatars.githubusercontent.com/u/873981?v=3","gravatar_id":"","url":"https://api.github.com/users/dockyard","html_url":"https://github.com/dockyard","followers_url":"https://api.github.com/users/dockyard/followers","following_url":"https://api.github.com/users/dockyard/following{/other_user}","gists_url":"https://api.github.com/users/dockyard/gists{/gist_id}","starred_url":"https://api.github.com/users/dockyard/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dockyard/subscriptions","organizations_url":"https://api.github.com/users/dockyard/orgs","repos_url":"https://api.github.com/users/dockyard/repos","events_url":"https://api.github.com/users/dockyard/events{/privacy}","received_events_url":"https://api.github.com/users/dockyard/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/dockyard/reefpoints","description":"DockYard Blog","fork":false,"url":"https://api.github.com/repos/dockyard/reefpoints","forks_url":"https://api.github.com/repos/dockyard/reefpoints/forks","keys_url":"https://api.github.com/repos/dockyard/reefpoints/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dockyard/reefpoints/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dockyard/reefpoints/teams","hooks_url":"https://api.github.com/repos/dockyard/reefpoints/hooks","issue_events_url":"https://api.github.com/repos/dockyard/reefpoints/issues/events{/number}","events_url":"https://api.github.com/repos/dockyard/reefpoints/events","assignees_url":"https://api.github.com/repos/dockyard/reefpoints/assignees{/user}","branches_url":"https://api.github.com/repos/dockyard/reefpoints/branches{/branch}","tags_url":"https://api.github.com/repos/dockyard/reefpoints/tags","blobs_url":"https://api.github.com/repos/dockyard/reefpoints/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dockyard/reefpoints/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dockyard/reefpoints/git/refs{/sha}","trees_url":"https://api.github.com/repos/dockyard/reefpoints/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dockyard/reefpoints/statuses/{sha}","languages_url":"https://api.github.com/repos/dockyard/reefpoints/languages","stargazers_url":"https://api.github.com/repos/dockyard/reefpoints/stargazers","contributors_url":"https://api.github.com/repos/dockyard/reefpoints/contributors","subscribers_url":"https://api.github.com/repos/dockyard/reefpoints/subscribers","subscription_url":"https://api.github.com/repos/dockyard/reefpoints/subscription","commits_url":"https://api.github.com/repos/dockyard/reefpoints/commits{/sha}","git_commits_url":"https://api.github.com/repos/dockyard/reefpoints/git/commits{/sha}","comments_url":"https://api.github.com/repos/dockyard/reefpoints/comments{/number}","issue_comment_url":"https://api.github.com/repos/dockyard/reefpoints/issues/comments{/number}","contents_url":"https://api.github.com/repos/dockyard/reefpoints/contents/{+path}","compare_url":"https://api.github.com/repos/dockyard/reefpoints/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dockyard/reefpoints/merges","archive_url":"https://api.github.com/repos/dockyard/reefpoints/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dockyard/reefpoints/downloads","issues_url":"https://api.github.com/repos/dockyard/reefpoints/issues{/number}","pulls_url":"https://api.github.com/repos/dockyard/reefpoints/pulls{/number}","milestones_url":"https://api.github.com/repos/dockyard/reefpoints/milestones{/number}","notifications_url":"https://api.github.com/repos/dockyard/reefpoints/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dockyard/reefpoints/labels{/name}","releases_url":"https://api.github.com/repos/dockyard/reefpoints/releases{/id}","deployments_url":"https://api.github.com/repos/dockyard/reefpoints/deployments","created_at":"2011-08-24T16:55:40Z","updated_at":"2016-01-08T22:43:24Z","pushed_at":"2016-01-31T17:13:18Z","git_url":"git://github.com/dockyard/reefpoints.git","ssh_url":"git@github.com:dockyard/reefpoints.git","clone_url":"https://github.com/dockyard/reefpoints.git","svn_url":"https://github.com/dockyard/reefpoints","homepage":"https://dockyard.com/blog","size":86847,"stargazers_count":35,"watchers_count":35,"language":"CSS","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":63,"mirror_url":null,"open_issues_count":15,"forks":63,"open_issues":15,"watchers":35,"default_branch":"master"}},"base":{"label":"dockyard:master","ref":"master","sha":"c4ee5af32db0fbc0c36e747ecf9fb6f6f27a692e","user":{"login":"dockyard","id":873981,"avatar_url":"https://avatars.githubusercontent.com/u/873981?v=3","gravatar_id":"","url":"https://api.github.com/users/dockyard","html_url":"https://github.com/dockyard","followers_url":"https://api.github.com/users/dockyard/followers","following_url":"https://api.github.com/users/dockyard/following{/other_user}","gists_url":"https://api.github.com/users/dockyard/gists{/gist_id}","starred_url":"https://api.github.com/users/dockyard/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dockyard/subscriptions","organizations_url":"https://api.github.com/users/dockyard/orgs","repos_url":"https://api.github.com/users/dockyard/repos","events_url":"https://api.github.com/users/dockyard/events{/privacy}","received_events_url":"https://api.github.com/users/dockyard/received_events","type":"Organization","site_admin":false},"repo":{"id":2262874,"name":"reefpoints","full_name":"dockyard/reefpoints","owner":{"login":"dockyard","id":873981,"avatar_url":"https://avatars.githubusercontent.com/u/873981?v=3","gravatar_id":"","url":"https://api.github.com/users/dockyard","html_url":"https://github.com/dockyard","followers_url":"https://api.github.com/users/dockyard/followers","following_url":"https://api.github.com/users/dockyard/following{/other_user}","gists_url":"https://api.github.com/users/dockyard/gists{/gist_id}","starred_url":"https://api.github.com/users/dockyard/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dockyard/subscriptions","organizations_url":"https://api.github.com/users/dockyard/orgs","repos_url":"https://api.github.com/users/dockyard/repos","events_url":"https://api.github.com/users/dockyard/events{/privacy}","received_events_url":"https://api.github.com/users/dockyard/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/dockyard/reefpoints","description":"DockYard Blog","fork":false,"url":"https://api.github.com/repos/dockyard/reefpoints","forks_url":"https://api.github.com/repos/dockyard/reefpoints/forks","keys_url":"https://api.github.com/repos/dockyard/reefpoints/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dockyard/reefpoints/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dockyard/reefpoints/teams","hooks_url":"https://api.github.com/repos/dockyard/reefpoints/hooks","issue_events_url":"https://api.github.com/repos/dockyard/reefpoints/issues/events{/number}","events_url":"https://api.github.com/repos/dockyard/reefpoints/events","assignees_url":"https://api.github.com/repos/dockyard/reefpoints/assignees{/user}","branches_url":"https://api.github.com/repos/dockyard/reefpoints/branches{/branch}","tags_url":"https://api.github.com/repos/dockyard/reefpoints/tags","blobs_url":"https://api.github.com/repos/dockyard/reefpoints/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dockyard/reefpoints/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dockyard/reefpoints/git/refs{/sha}","trees_url":"https://api.github.com/repos/dockyard/reefpoints/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dockyard/reefpoints/statuses/{sha}","languages_url":"https://api.github.com/repos/dockyard/reefpoints/languages","stargazers_url":"https://api.github.com/repos/dockyard/reefpoints/stargazers","contributors_url":"https://api.github.com/repos/dockyard/reefpoints/contributors","subscribers_url":"https://api.github.com/repos/dockyard/reefpoints/subscribers","subscription_url":"https://api.github.com/repos/dockyard/reefpoints/subscription","commits_url":"https://api.github.com/repos/dockyard/reefpoints/commits{/sha}","git_commits_url":"https://api.github.com/repos/dockyard/reefpoints/git/commits{/sha}","comments_url":"https://api.github.com/repos/dockyard/reefpoints/comments{/number}","issue_comment_url":"https://api.github.com/repos/dockyard/reefpoints/issues/comments{/number}","contents_url":"https://api.github.com/repos/dockyard/reefpoints/contents/{+path}","compare_url":"https://api.github.com/repos/dockyard/reefpoints/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dockyard/reefpoints/merges","archive_url":"https://api.github.com/repos/dockyard/reefpoints/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dockyard/reefpoints/downloads","issues_url":"https://api.github.com/repos/dockyard/reefpoints/issues{/number}","pulls_url":"https://api.github.com/repos/dockyard/reefpoints/pulls{/number}","milestones_url":"https://api.github.com/repos/dockyard/reefpoints/milestones{/number}","notifications_url":"https://api.github.com/repos/dockyard/reefpoints/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dockyard/reefpoints/labels{/name}","releases_url":"https://api.github.com/repos/dockyard/reefpoints/releases{/id}","deployments_url":"https://api.github.com/repos/dockyard/reefpoints/deployments","created_at":"2011-08-24T16:55:40Z","updated_at":"2016-01-08T22:43:24Z","pushed_at":"2016-01-31T17:13:18Z","git_url":"git://github.com/dockyard/reefpoints.git","ssh_url":"git@github.com:dockyard/reefpoints.git","clone_url":"https://github.com/dockyard/reefpoints.git","svn_url":"https://github.com/dockyard/reefpoints","homepage":"https://dockyard.com/blog","size":86847,"stargazers_count":35,"watchers_count":35,"language":"CSS","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":63,"mirror_url":null,"open_issues_count":15,"forks":63,"open_issues":15,"watchers":35,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dockyard/reefpoints/pulls/444"},"html":{"href":"https://github.com/dockyard/reefpoints/pull/444"},"issue":{"href":"https://api.github.com/repos/dockyard/reefpoints/issues/444"},"comments":{"href":"https://api.github.com/repos/dockyard/reefpoints/issues/444/comments"},"review_comments":{"href":"https://api.github.com/repos/dockyard/reefpoints/pulls/444/comments"},"review_comment":{"href":"https://api.github.com/repos/dockyard/reefpoints/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/dockyard/reefpoints/pulls/444/commits"},"statuses":{"href":"https://api.github.com/repos/dockyard/reefpoints/statuses/7a916bcbcfac55c056ce92f8751d1a04e362f055"}}}}