defmodule Sandbox do
def fast_cars_index do
fast_cars =
[
%{color: "Red", make: "Mclaren", mileage: 15641.469},
%{color: "Blue", make: "Ferrari", mileage: 120012.481},
%{color: "Red", make: "Ferrari", mileage: 29831.021},
%{color: "Black", make: "Ferrari", mileage: 24030.674},
%{color: "Cobalt", make: "Ferrari", mileage: 412.811},
%{color: "Blue", make: "Koenigsegg", mileage: 250.762},
%{color: "Cobalt", make: "Koenigsegg", mileage: 1297.76},
%{color: "Titanium", make: "Koenigsegg", mileage: 5360.336},
%{color: "Blue", make: "Maserati", mileage: 255.78}
]
Enum.map(
fast_cars,
fn %{color: color, make: make, mileage: mileage}
->
%{
make: make,
inserted_at: DateTime.truncate(DateTime.utc_now, :second),
updated_at: DateTime.truncate(DateTime.utc_now, :second),
%{
color: color,
mileage: mileage
}
}
end)
end
end
iex()> recompile
Compiling 1 file (.ex)
== Compilation error in file lib/Sandbox.ex ==
** (SyntaxError) lib/Sandbox.ex:25: syntax error before: '%{}'
(elixir 1.10.3) lib/kernel/parallel_compiler.ex:304: anonymous fn/4 in Kernel.ParallelCompiler.spawn_workers/7
** (exit) shutdown: 1
(mix 1.10.3) lib/mix/tasks/compile.all.ex:62: Mix.Tasks.Compile.All.do_compile/4
(mix 1.10.3) lib/mix/tasks/compile.all.ex:27: anonymous fn/2 in Mix.Tasks.Compile.All.run/1
(mix 1.10.3) lib/mix/tasks/compile.all.ex:43: Mix.Tasks.Compile.All.with_logger_app/2
(mix 1.10.3) lib/mix/task.ex:330: Mix.Task.run_task/3
(mix 1.10.3) lib/mix/tasks/compile.ex:96: Mix.Tasks.Compile.run/1
(mix 1.10.3) lib/mix/task.ex:330: Mix.Task.run_task/3
(iex 1.10.3) lib/iex/helpers.ex:104: IEx.Helpers.recompile/1
As you can see, I’m trying to create a list of maps within maps. What’s the correct syntax for this? Thanks for you assistance!