Strech / avrora

A convenient Elixir library to work with Avro messages, schemas and Confluent® Schema Registry
https://hexdocs.pm/avrora
MIT License
97 stars 33 forks source link

Allow encode/2 to receive opts in any order #112

Closed rewritten closed 9 months ago

rewritten commented 9 months ago

The usual understanding, when a function accepts a keyword list as a last "options" argument, is that those options can be given in any order. On the other side, the current code pattern matches the list in exact order, so this expectation is not fulfilled, and this code raises a FunctionClauseError:

Avrora.encode(payload, format: :plain, schema_name: "io.confluent.Messenger")

This PR switches out the pattern matching on options, and uses appropriate Keyword functions to extract the values.

Strech commented 9 months ago

@rewritten Thanks a lot for the fix. I've changed an approach and for just 2 options, I would prefer pattern matching as a faster way. In addition, I've changed the test description to follow an established format.

💜