The second check is to allow expansion:
local event_filter = {
{filter="name", name="spoilables-freezer"},
{filter="name", name="cargo-wagon-freezer"},
}
local function on_built(event)
local entity = event.entity
if entity.name == "spoilables-freezer" then
elseif entity.name == "cargo-wagon-freezer" then
end
end
The filter causes on_built to only run in these two cases. Then I am going to deal with exact cases with if statements. (yeah, hashmaps blabla tables are better if there are many entities)
The lambda is how im used to writing, but yes, the other way is more concise.
All in all, these are player build listeners, they don't run by themselves.
They might be only ran 100 times in the whole game, so the performance is not critical, no need to do premature optimization.
Optimization of other functions like run on_nth_tick is a priority.