Skip to content

Keyword.merge behaviour when a list is the second argument (docs/test) #5395

Closed
@PragTob

Description

@PragTob

Environment

  • Elixir version (elixir -v):
Erlang/OTP 19 [erts-8.0] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false]

Elixir 1.3.4
  • Operating system:
tobi@happy ~ $ uname -a
Linux happy 3.19.0-32-generic #37~14.04.1-Ubuntu SMP Thu Oct 22 09:41:40 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

Current behavior

The current behaviour is that when Keyword.merge is called with a normal list as the second argument it just appends the list.

iex(1)> Keyword.merge [a: 1], [b: 2]
[a: 1, b: 2]
iex(2)> Keyword.merge [a: 1], [2, 3]
[{:a, 1}, 2, 3]

Expected behavior

Not sure, part of what this is about :) I see 3 options:

  1. throw an error (as the second argument is no keyword list).
  2. The current behavior can be argued for and could be declared wanted behaviour, in that case I'd want to add a unit test for it and some documentation (there doesn't seem to be any for this case atm)
  3. it could be declared "undefined behaviour" and marked as such

I'd have expected 1.) to happen but through the internal representation can also understand that 2.) might be a good course of action.

Thanks for all your effort + Cheers,
Tobi

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions