Demonstrate update_in to manipulate nested struct values
This commit is contained in:
@@ -54,4 +54,9 @@ defmodule Structs do
|
|||||||
airline = %Airline{plane: %Plane{maker: :boeing}}
|
airline = %Airline{plane: %Plane{maker: :boeing}}
|
||||||
assert put_in(airline.plane.maker, :airbus) == ___
|
assert put_in(airline.plane.maker, :airbus) == ___
|
||||||
end
|
end
|
||||||
|
|
||||||
|
koan "Use the update_in macro to modify a nested value" do
|
||||||
|
airline = %Airline{plane: %Plane{maker: :boeing, passengers: 200}}
|
||||||
|
assert update_in(airline.plane.passengers, &(&1 + 2)) == ___
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ defmodule StructsTests do
|
|||||||
{:multiple, [true, false]},
|
{:multiple, [true, false]},
|
||||||
{:ok, 22},
|
{:ok, 22},
|
||||||
%Structs.Airline{plane: %Structs.Plane{maker: :airbus}, name: "Southwest"},
|
%Structs.Airline{plane: %Structs.Plane{maker: :airbus}, name: "Southwest"},
|
||||||
|
%Structs.Airline{plane: %Structs.Plane{maker: :boeing, passengers: 202}, name: "Southwest"},
|
||||||
]
|
]
|
||||||
|
|
||||||
test_all(Structs, answers)
|
test_all(Structs, answers)
|
||||||
|
|||||||
Reference in New Issue
Block a user