Demonstrate put_in using atoms to manipulate nested values of a nested
Map
This commit is contained in:
@@ -59,4 +59,14 @@ defmodule Structs do
|
|||||||
airline = %Airline{plane: %Plane{maker: :boeing, passengers: 200}}
|
airline = %Airline{plane: %Plane{maker: :boeing, passengers: 200}}
|
||||||
assert update_in(airline.plane.passengers, &(&1 + 2)) == ___
|
assert update_in(airline.plane.passengers, &(&1 + 2)) == ___
|
||||||
end
|
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
|
end
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ defmodule StructsTests do
|
|||||||
{: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"},
|
%Structs.Airline{plane: %Structs.Plane{maker: :boeing, passengers: 202}, name: "Southwest"},
|
||||||
|
%{plane: %{maker: :cessna}, name: "Southwest"},
|
||||||
]
|
]
|
||||||
|
|
||||||
test_all(Structs, answers)
|
test_all(Structs, answers)
|
||||||
|
|||||||
Reference in New Issue
Block a user