I am trying to write tests in Elixir that call Erlang code similar to this:
foo([{property_one = P1, property_two = P2}|_] = Rows) when P1 =/= P2 ->
erlang:display("function head one"),
foo(Rows) ->
erlang:display("function head two"),
Rows.
I think that an Elixir keyword list would be the correct data type to pass to this function, but I cannot seem to construct it properly. This is the code I'm trying to call it with:
:module.foo([[property_one: "A", property_two: "B"]])
But this code goes direct to function head two. Where am I going wrong?
Update: Going to git history for the file revealed that a record declaration had been dropped somewhere along the way. Modifying the code to:
foo([#record{property_one = P1, property_two = P2}|_] = Rows)
fixed all problems
foofunction? That first clause only matches a list starting with the tuple{property_one, property_two}. This should match it::module.foo([{:property_one, :property_two}]).P1will always be:property_oneandP2will always be:property_twowith the current Erlang code.{in the pattern? Records in Erlang are stored as plain tuples without property key names. To create Erlang records in Elixir, you should use theRecordmodule as explained here: hexdocs.pm/elixir/Record.html.