From 516be35df9b77e4e92d445554730d379d168fea8 Mon Sep 17 00:00:00 2001 From: srufle Date: Sun, 22 Jan 2017 10:46:51 -0700 Subject: [PATCH] Demonstrate put_in to manipulate nested struct values --- lib/koans/11_structs.ex | 9 +++++++++ test/koans/structs_koans_test.exs | 1 + 2 files changed, 10 insertions(+) diff --git a/lib/koans/11_structs.ex b/lib/koans/11_structs.ex index 1c33fd5..7b4945f 100644 --- a/lib/koans/11_structs.ex +++ b/lib/koans/11_structs.ex @@ -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 diff --git a/test/koans/structs_koans_test.exs b/test/koans/structs_koans_test.exs index 92622b9..8d975fa 100644 --- a/test/koans/structs_koans_test.exs +++ b/test/koans/structs_koans_test.exs @@ -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)