I found that typing and testing all the small code snippets added to my Elixir “muscle memory” and seeing what standard practices look like. For example, when updating the todo list example, I would not have thought of passing a lambda function for the update vs. just passing new data. The lambda function provides much more flexibility at the cost of some slight complexity increase (at least I’m still seeing it as a complexity increase at this stage).
I need to get more comfortable with updating structures. Spending a lot of time staring at this code before comprehending it.
def delete_entry(todo_list, entry_id) do
%TodoList{todo_list | entries: Map.delete(todo_list.entries, entry_id)}
end
CSV Import Exercise
My solution was functionally identical to Saša’s except I tried to do everything inline in a single pipe.
Saša broke out the pipelined actions into two functions (read_lines
and create_entries
).
Also used a multi-step anonymous function in a Stream.map
.
I need to remember that anonymous functions don’t need to be simple one-liners.