-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Add Map.intersect/2 and Map.intersect/3 #12336
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
2b15fbd
to
2439587
Compare
lib/elixir/lib/map.ex
Outdated
`map1`), and `value2` (the value of `key` in `map2`). The value returned by | ||
`fun` is used as the value under `key` in the resulting map. | ||
|
||
Inlined by the compiler. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not the case, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What exactly?
map1
), andvalue2
(the value ofkey
inmap2
). The value returned by
fun
is used as the value underkey
in the resulting map.
I tried to adapt the same wording used in Map.merge
, akin to https://www.erlang.org/doc/man/maps.html#intersect_with-3.
Inlined by the compiler.
I cargo-culted this since other functions that just pass to Erlang functions included it (even without defdelegate
). E.g.
Line 275 in bc0cf0b
def has_key?(map, key), do: :maps.is_key(key, map) |
Line 388 in bc0cf0b
:maps.update(key, value, map) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK you'd have to add the inline rules at https://github.com/elixir-lang/elixir/blob/main/lib/elixir/src/elixir_rewrite.erl, which I believe is expected in this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer documentation use language based on the Elixir MapSet
documentation rather than the Erlang :maps
docs. For example MapSet.intersection/2
docs include
Returns a set containing only members that map_set1 and map_set2 have in common.
This is much nicer than
Intersects two sets into one.
Co-authored-by: Malian <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fantastic!
Co-authored-by: Andrea Leopardi <[email protected]>
💚 💙 💜 💛 ❤️ |
Following up from https://elixirforum.com/t/map-intersection-2/53121/12. I didn't see any duplicates, hopefully it's okay I pushed up.
My first PR, so tried to follow https://github.com/elixir-lang/elixir#contributing & https://github.com/elixir-lang/elixir/blob/main/CODE_OF_CONDUCT.md as best as I could.
:maps.intersect/2
&:maps.intersect_with/3
.Map.merge/3
, including the tests & docs. More than happy to extend these.KeywordTest
since I wasn't sure if extendingKeyword
would be out-of-scope. Happy to add aKeyword.intersect
function as well, if desired.make test_stdlib
resulted in1948 doctests, 4187 tests, 0 failures, 13 excluded
./bin/iex