Demonstrate update_in to manipulate nested struct values

This commit is contained in:
srufle
2017-01-22 11:12:49 -07:00
parent 516be35df9
commit d467985778
2 changed files with 6 additions and 0 deletions

View File

@@ -54,4 +54,9 @@ defmodule Structs do
airline = %Airline{plane: %Plane{maker: :boeing}}
assert put_in(airline.plane.maker, :airbus) == ___
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

View File

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