Complete maps.erl take/2 etc.#2355
Open
petermm wants to merge 3 commits into
Open
Conversation
OTP-compatible implementations of maps:take/2,
maps:update_with/3, maps:update_with/4, maps:with/2 and
maps:without/2 to the estdlib maps module.
Each function preserves OTP error semantics:
- {badmap, Map} when the map argument is not a map (taking
precedence over badarg when multiple arguments are wrong)
- badarg when Keys is not a list (with/2, without/2) or Fun
is not a function of arity 1 (update_with/3,4)
- {badkey, Key} from update_with/3 only when Map is a valid
map, Fun is arity-1 and Key is missing
- update_with/4 inserts Init verbatim without invoking Fun
when the key is absent
Tests cover the happy paths plus error precedence, duplicate
keys in with/without, a value of the atom 'error' in take/2
(must not be confused with the missing-key result), and the
guarantee that update_with/4 does not call Fun on insert.
Signed-off-by: Peter M <petermm@gmail.com>
…iterator_valid
Add six pure Erlang functions to the estdlib maps module for
improved OTP compatibility:
- filtermap/2: Combined filter and map operation
- intersect/2: Map intersection (values from second map)
- intersect_with/3: Map intersection with value combiner
- groups_from_list/2: Group list elements by key function
- groups_from_list/3: Group with value transformation
- is_iterator_valid/1: Iterator validation (internal, exported)
All functions follow OTP semantics exactly, include comprehensive
error handling ({badmap, Map}, badarg), work with both maps and
iterators where applicable, and have full test coverage.
Signed-off-by: Peter M <petermm@gmail.com>
Signed-off-by: Peter M <petermm@gmail.com>
pguyot
reviewed
Jul 5, 2026
| %% An iterator becomes invalid if it has been exhausted or if the underlying | ||
| %% map has been modified. | ||
| %% | ||
| %% This is an internal function, primarily used by other functions in this module. |
| %% `Combiner(Key, Value1, Value2)' where `Value1' is from `Map1' and `Value2' | ||
| %% is from `Map2'. | ||
| %% | ||
| %% This function raises a `badmap' error if either `Map1' or `Map2' is not a map, |
Collaborator
There was a problem hiding this comment.
It seems error precedence diverges from OTP. This could be asserted with testing maps:intersect_with(BadCombiner, NotAMap, #{})
| - Added USB CDC port drivers for ESP32, RP2, and STM32 platforms | ||
| - Added `maps:take/2`, `maps:update_with/3`, `maps:update_with/4`, `maps:with/2`, | ||
| `maps:without/2`, `maps:filtermap/2`, `maps:intersect/2`, `maps:intersect_with/3`, | ||
| `maps:groups_from_list/2` and `maps:groups_from_list/3` to the estdlib `maps` module |
Collaborator
There was a problem hiding this comment.
This should be shortened (llm verbosity it seems) or it should mention is_iterator_valid/1
| ), | ||
| #{b => 20, d => 40} | ||
| ), | ||
| %% Works with iterators |
Collaborator
There was a problem hiding this comment.
We need to test ordered iterators as well.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
These changes are made under both the "Apache 2.0" and the "GNU Lesser General
Public License 2.1 or later" license terms (dual license).
SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later