Why keyword lists for opts instead of maps?

Personally, I like KW lists because of a) order, b) syntactic sugar.

foo( bar, a: 1, b: 2, c: 3) 

is so much nicer than:

foo( bar, %{ a: 1, b: 2, c: 2})

When I need accessing the options in a map-like fashion, I’m willing to pay the price of having the KW list converted to a map in my function.

Besides, maybe what you sometimes need is precisely a list-like pattern matching e.g.:

def foo( bar, [ a: 1 | [ b: 2 | _]] = opts)
1 Like