Demonstrate put_in to manipulate nested struct values
This commit is contained in:
@@ -45,4 +45,13 @@ defmodule Structs do
|
||||
|
||||
assert Map.fetch(silvia, :age) == ___
|
||||
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
|
||||
|
||||
@@ -10,6 +10,7 @@ defmodule StructsTests do
|
||||
33,
|
||||
{:multiple, [true, false]},
|
||||
{:ok, 22},
|
||||
%Structs.Airline{plane: %Structs.Plane{maker: :airbus}, name: "Southwest"},
|
||||
]
|
||||
|
||||
test_all(Structs, answers)
|
||||
|
||||
Reference in New Issue
Block a user