Demonstrate put_in using atoms to manipulate nested values of a nested

Map
This commit is contained in:
srufle
2017-01-22 11:15:17 -07:00
parent d467985778
commit 55f1648bbd
2 changed files with 11 additions and 0 deletions

View File

@@ -59,4 +59,14 @@ defmodule Structs do
airline = %Airline{plane: %Plane{maker: :boeing, passengers: 200}}
assert update_in(airline.plane.passengers, &(&1 + 2)) == ___
end
koan "Use the put_in macro with atoms to replace a nested value in a non-struct" do
airline = %{
plane: %{
maker: :boeing
},
name: "Southwest"
}
assert put_in(airline[:plane][:maker], :cessna) == ___
end
end

View File

@@ -12,6 +12,7 @@ defmodule StructsTests do
{:ok, 22},
%Structs.Airline{plane: %Structs.Plane{maker: :airbus}, name: "Southwest"},
%Structs.Airline{plane: %Structs.Plane{maker: :boeing, passengers: 202}, name: "Southwest"},
%{plane: %{maker: :cessna}, name: "Southwest"},
]
test_all(Structs, answers)