Demonstrate put_in to manipulate nested struct values

This commit is contained in:
srufle
2017-01-22 10:46:51 -07:00
parent 3b1980b7d9
commit 516be35df9
2 changed files with 10 additions and 0 deletions

View File

@@ -45,4 +45,13 @@ defmodule Structs do
assert Map.fetch(silvia, :age) == ___ assert Map.fetch(silvia, :age) == ___
end end
defmodule Airline do
defstruct plane: %Plane{}, name: "Southwest"
end
koan "Use the put_in macro to replace a nested value" do
airline = %Airline{plane: %Plane{maker: :boeing}}
assert put_in(airline.plane.maker, :airbus) == ___
end
end end

View File

@@ -10,6 +10,7 @@ defmodule StructsTests do
33, 33,
{:multiple, [true, false]}, {:multiple, [true, false]},
{:ok, 22}, {:ok, 22},
%Structs.Airline{plane: %Structs.Plane{maker: :airbus}, name: "Southwest"},
] ]
test_all(Structs, answers) test_all(Structs, answers)