Complete maps.erl take/2 etc. by petermm · Pull Request #2355 · atomvm/AtomVM · GitHub
Skip to content

Complete maps.erl take/2 etc. - #2355

Open
petermm wants to merge 5 commits into
atomvm:release-0.7from
petermm:add-maps-take-update-with-with-without
Open

petermm wants to merge 5 commits into
atomvm:release-0.7from
petermm:add-maps-take-update-with-with-without

Conversation

@petermm

@petermm petermm commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

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

Comment thread libs/estdlib/src/maps.erl Outdated
Comment thread libs/estdlib/src/maps.erl Outdated
Comment thread CHANGELOG.md Outdated
Comment thread tests/libs/estdlib/test_maps.erl
@petermm
petermm marked this pull request as draft July 7, 2026 08:51
@petermm
petermm force-pushed the add-maps-take-update-with-with-without branch from 3683d22 to 00b26a2 Compare July 10, 2026 15:16
@petermm
petermm force-pushed the add-maps-take-update-with-with-without branch from 00b26a2 to 0ba30dd Compare July 23, 2026 09:34
@petermm

petermm commented Jul 23, 2026

Copy link
Copy Markdown
Contributor Author

@petermm
petermm marked this pull request as ready for review July 23, 2026 12:05
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>
Align map helper error precedence and iterator handling with current OTP semantics, including ordered and key-value iterator forms.

Harden maps:next/1 against invalid numeric positions and malformed ordered iterators, and expand estdlib regression coverage for callback order, iterator validation, and badarg/badmap behavior.

Signed-off-by: Peter M <petermm@gmail.com>
Signed-off-by: Peter M <petermm@gmail.com>
@petermm
petermm force-pushed the add-maps-take-update-with-with-without branch from 0ba30dd to b032806 Compare October 13, 2026 19:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants