elixir-koans
elixir-koans copied to clipboard
Koans might be more educational when inverted
Hi, just a thought because I'm halfway through the koans and I'm pretty sure that I have missed a lot of class (?) functions because I wasn't writing them. The asserts might be more educational when inverted, i.e. instead of:
assert Map.merge(%{first_name: "Jon"}, %{last_name: "Snow"}) == ___
it was:
assert %{first_name: "Jon", last_name: "Snow"} == Map.merge(___, ___)
Or something similar, so that when adding an answer, your eyes are drawn to the function being used.
Anyway, lovely resource, thanks for maintaining!
Thanks for the suggestion! Very interesting idea 💡
I would say that generally speaking, the goal of lessons like this is to encourage the learner to seek out the documentation for what is not understand and use that to produce an answer. The convenient thing about pure functions is that they are deterministic (did I get that right?). That is, in this example, there is exactly one result that is produced from the given input. In the proposed form, there are many inputs that produce the same result, e.g.
-
Map.merge(%{first_name: "Jon"}, %{last_name: "Snow"})
-
Map.merge(%{}, %{first_name: "Jon", last_name: "Snow"})
-
Map.merge(%{first_name: "Brian", last_name: "Kung"}, %{first_name: "Jon", last_name: "Snow"})
For that reason, I tend to think that the existing form is more concrete and therefore more enlightening. Additional examples might be included (like those listed above) to emphasize other truths, like for e.g. Map.merge overwrites existing values.
In fairness, this is my "right now" thoughts on this issue, and not necessarily based on the decision made at the time of writing the example(s).
Glad you've found this project useful! Thank you for the discussion.