Complete maps.erl take/2 etc.#2355
Conversation
3683d22 to
00b26a2
Compare
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>
00b26a2 to
0ba30dd
Compare
PR Review: OTP-compatible
|
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