Add support for keyword lists in Access.key/2 and Access.key!/1#15470
Add support for keyword lists in Access.key/2 and Access.key!/1#15470tudborg wants to merge 1 commit into
Conversation
|
I wasn't sure how defensive to be in the returned accessor function.
I could be more defensive and require the container is either I'm currently raising an I think it is important that regardless of container type, the raise is the same Thoughts? |
|
We are usually not that defensive when it comes to keywords. We may error but it is not a guarantee. Note the Thoughts on the |
ed7aecb to
61be27c
Compare
|
Overall looks good, but we might need to be slightly more defensive in the following case or bugs might slip: iex> put_in([1], [Access.key(:foo)], :bar)
[{:foo, :bar}, 1]The raw key fails with a non-optimal error but at least it fails: iex> put_in([1], [:foo], :bar)
** (FunctionClauseError) no function clause matching in Keyword.get_and_update/4 |
This adds Keyword list support to
Access.key/2andAccess.key!/1.Original discussion in #15468
I'd like to move some of. the doctest into
access_test.exsinstead.Access.keywas only tested in doctests, but the other accessors have dedicateddescribeinaccess_test.exs,but this is good enough for a discussion around the feature. :)