Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added support for configuring pins and width for sdmmc on ESP32
- Added support for map comprehensions
- Added USB CDC port drivers for ESP32, RP2, and STM32 platforms
- Added `lists:mapfoldr/3`

### Changed
- Updated network type db() to dbm() to reflect the actual representation of the type
Expand Down
17 changes: 17 additions & 0 deletions libs/estdlib/src/lists.erl
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
foldl/3,
foldr/3,
mapfoldl/3,
mapfoldr/3,
all/2,
any/2,
flatten/1,
Expand Down Expand Up @@ -412,6 +413,22 @@ mapfoldl0(Fun, {List1, Acc0}, [H | T]) ->
{B, Acc1} = Fun(H, Acc0),
mapfoldl0(Fun, {[B | List1], Acc1}, T).

%%-----------------------------------------------------------------------------
%% @param Fun the function to apply
%% @param Acc0 the initial accumulator
%% @param List the list over which to fold
%% @returns the result of mapping and folding Fun over List, from right to left
%% @doc Combine `map/2' and `foldr/3' in one pass.
%% @end
%%-----------------------------------------------------------------------------
-spec mapfoldr(fun((A, Acc) -> {B, Acc}), Acc, [A]) -> {[B], Acc}.
mapfoldr(_Fun, Acc0, []) ->
{[], Acc0};
mapfoldr(Fun, Acc0, [H | T]) ->
{Bs, Acc1} = mapfoldr(Fun, Acc0, T),
{B, Acc2} = Fun(H, Acc1),
{[B | Bs], Acc2}.

%%-----------------------------------------------------------------------------
%% @equiv foldl(Fun, Acc0, reverse(List))
%% @doc Fold over a list of terms, from right to left, applying Fun(E, Accum)
Expand Down
11 changes: 11 additions & 0 deletions tests/libs/estdlib/test_lists.erl
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,17 @@
lists:mapfoldl(fun(X, A) -> {X * A, A + 1} end, 1, [1, 2, 3])
),
?ASSERT_ERROR(lists:mapfoldl(fun(X, A) -> {X * A, A + 1} end, 1, foo), function_clause),
ok = test_mapfoldr(),
ok.

test_mapfoldr() ->
?ASSERT_MATCH({[], 1}, lists:mapfoldr(fun(X, A) -> {X * A, A + 1} end, 1, [])),
%% Right-to-left: the accumulator visits 3, then 2, then 1.
?ASSERT_MATCH(
{[3, 4, 3], 4},
lists:mapfoldr(fun(X, A) -> {X * A, A + 1} end, 1, [1, 2, 3])
),
?ASSERT_ERROR(lists:mapfoldr(fun(X, A) -> {X * A, A + 1} end, 1, foo), function_clause),
ok.

test_append() ->
Expand All @@ -488,7 +499,7 @@
?ASSERT_ERROR(lists:append(1), function_clause),
?ASSERT_MATCH(lists:append("abc", "def"), "abcdef"),
?ASSERT_MATCH(lists:append([1, 2], [3, 4]), [1, 2, 3, 4]),
?ASSERT_ERROR(lists:append(1, 3), badarg),

Check warning on line 502 in tests/libs/estdlib/test_lists.erl

View workflow job for this annotation

GitHub Actions / build-and-test (macos-26, 26, mbedtls@3)

the call to lists:append/2 will fail with a 'badarg' exception

Check warning on line 502 in tests/libs/estdlib/test_lists.erl

View workflow job for this annotation

GitHub Actions / run-tests (macos-15, 26)

the call to lists:append/2 will fail with a 'badarg' exception

Check warning on line 502 in tests/libs/estdlib/test_lists.erl

View workflow job for this annotation

GitHub Actions / Analyze (cpp)

the call to lists:append/2 will fail with a 'badarg' exception

Check warning on line 502 in tests/libs/estdlib/test_lists.erl

View workflow job for this annotation

GitHub Actions / build-and-test (macos-14, 27, mbedtls@3)

the call to lists:append/2 will fail with a 'badarg' exception

Check warning on line 502 in tests/libs/estdlib/test_lists.erl

View workflow job for this annotation

GitHub Actions / run-tests (macos-15, 27)

the call to lists:append/2 will fail with a 'badarg' exception

Check warning on line 502 in tests/libs/estdlib/test_lists.erl

View workflow job for this annotation

GitHub Actions / build-and-test (macos-15-intel, 28, mbedtls@3)

the call to lists:append/2 will fail with a 'badarg' exception

Check warning on line 502 in tests/libs/estdlib/test_lists.erl

View workflow job for this annotation

GitHub Actions / build-and-test (macos-26, 27, mbedtls@3)

the call to lists:append/2 will fail with a 'badarg' exception

Check warning on line 502 in tests/libs/estdlib/test_lists.erl

View workflow job for this annotation

GitHub Actions / build-and-test (macos-15, 26, mbedtls@3)

the call to lists:append/2 will fail with a 'badarg' exception

Check warning on line 502 in tests/libs/estdlib/test_lists.erl

View workflow job for this annotation

GitHub Actions / build-and-test (macos-15, 28, mbedtls@3)

the call to lists:append/2 will fail with a 'badarg' exception

Check warning on line 502 in tests/libs/estdlib/test_lists.erl

View workflow job for this annotation

GitHub Actions / build-and-test (macos-15-intel, 26, mbedtls@3)

the call to lists:append/2 will fail with a 'badarg' exception

Check warning on line 502 in tests/libs/estdlib/test_lists.erl

View workflow job for this annotation

GitHub Actions / build-and-test (macos-15, 27, mbedtls@3)

the call to lists:append/2 will fail with a 'badarg' exception

Check warning on line 502 in tests/libs/estdlib/test_lists.erl

View workflow job for this annotation

GitHub Actions / build-and-test (riscv64-linux-gnu-gcc, 28, ubuntu-24.04, riscv64-linux-gnu-g++, -O2, 1.17, 3.24.0...

the call to lists:append/2 will fail with a 'badarg' exception

Check warning on line 502 in tests/libs/estdlib/test_lists.erl

View workflow job for this annotation

GitHub Actions / run-tests (macos-15, 28)

the call to lists:append/2 will fail with a 'badarg' exception

Check warning on line 502 in tests/libs/estdlib/test_lists.erl

View workflow job for this annotation

GitHub Actions / build-and-test (macos-14, 28, mbedtls@3, -DAVM_DISABLE_JIT=OFF)

the call to lists:append/2 will fail with a 'badarg' exception

Check warning on line 502 in tests/libs/estdlib/test_lists.erl

View workflow job for this annotation

GitHub Actions / build-and-test (macos-15-intel, 27, mbedtls@3)

the call to lists:append/2 will fail with a 'badarg' exception

Check warning on line 502 in tests/libs/estdlib/test_lists.erl

View workflow job for this annotation

GitHub Actions / build-and-test (cc, ubuntu-24.04-arm, c++)

the call to lists:append/2 will fail with a 'badarg' exception

Check warning on line 502 in tests/libs/estdlib/test_lists.erl

View workflow job for this annotation

GitHub Actions / build-and-test (macos-14, 26, mbedtls@3)

the call to lists:append/2 will fail with a 'badarg' exception

Check warning on line 502 in tests/libs/estdlib/test_lists.erl

View workflow job for this annotation

GitHub Actions / build-and-test (clang-13, clang++-13, clang-13, ubuntu-22.04)

the call to lists:append/2 will fail with a 'badarg' exception

Check warning on line 502 in tests/libs/estdlib/test_lists.erl

View workflow job for this annotation

GitHub Actions / build-and-test (macos-14, 28, mbedtls@3)

the call to lists:append/2 will fail with a 'badarg' exception

Check warning on line 502 in tests/libs/estdlib/test_lists.erl

View workflow job for this annotation

GitHub Actions / build-and-test (cc, ubuntu-24.04-arm, c++, -DAVM_DISABLE_JIT=OFF, aarch64)

the call to lists:append/2 will fail with a 'badarg' exception

Check warning on line 502 in tests/libs/estdlib/test_lists.erl

View workflow job for this annotation

GitHub Actions / build-and-test (macos-26, 28, mbedtls@3, -DAVM_DISABLE_JIT=OFF -DAVM_DISABLE_JIT_DWARF=OFF)

the call to lists:append/2 will fail with a 'badarg' exception

Check warning on line 502 in tests/libs/estdlib/test_lists.erl

View workflow job for this annotation

GitHub Actions / build-and-test (cc, 28, ubuntu-24.04-arm, c++, 1.17, 3.24.0, -DAVM_DISABLE_JIT=OFF -DAVM_DISABLE_...

the call to lists:append/2 will fail with a 'badarg' exception

Check warning on line 502 in tests/libs/estdlib/test_lists.erl

View workflow job for this annotation

GitHub Actions / build-and-test (macos-26, 28, mbedtls@3)

the call to lists:append/2 will fail with a 'badarg' exception

Check warning on line 502 in tests/libs/estdlib/test_lists.erl

View workflow job for this annotation

GitHub Actions / build-and-test (clang-12, clang++-12, clang-12, ubuntu-22.04)

the call to lists:append/2 will fail with a 'badarg' exception

Check warning on line 502 in tests/libs/estdlib/test_lists.erl

View workflow job for this annotation

GitHub Actions / build-and-test (gcc-13, 27)

the call to lists:append/2 will fail with a 'badarg' exception

Check warning on line 502 in tests/libs/estdlib/test_lists.erl

View workflow job for this annotation

GitHub Actions / build-and-test (clang-11, clang++-11, clang-11, ubuntu:20.04)

the call to lists:append/2 will fail with a 'badarg' exception

Check warning on line 502 in tests/libs/estdlib/test_lists.erl

View workflow job for this annotation

GitHub Actions / build-and-test (macos-15, 28, mbedtls@3, -DAVM_DISABLE_JIT=OFF)

the call to lists:append/2 will fail with a 'badarg' exception

Check warning on line 502 in tests/libs/estdlib/test_lists.erl

View workflow job for this annotation

GitHub Actions / build-and-test (gcc-9, g++-9, gcc-9 g++-9)

the call to lists:append/2 will fail with a 'badarg' exception

Check warning on line 502 in tests/libs/estdlib/test_lists.erl

View workflow job for this annotation

GitHub Actions / build-and-test (macos-15-intel, 28, mbedtls@3, -DAVM_DISABLE_JIT=OFF)

the call to lists:append/2 will fail with a 'badarg' exception

Check warning on line 502 in tests/libs/estdlib/test_lists.erl

View workflow job for this annotation

GitHub Actions / build-and-test (cc, c++, -DAVM_DISABLE_JIT=OFF, x86_64)

the call to lists:append/2 will fail with a 'badarg' exception

Check warning on line 502 in tests/libs/estdlib/test_lists.erl

View workflow job for this annotation

GitHub Actions / build-and-test (riscv64-linux-gnu-gcc, 28, ubuntu-24.04, riscv64-linux-gnu-g++, -O2, 1.17, 3.24.0...

the call to lists:append/2 will fail with a 'badarg' exception

Check warning on line 502 in tests/libs/estdlib/test_lists.erl

View workflow job for this annotation

GitHub Actions / build-and-test (clang-18, 26)

the call to lists:append/2 will fail with a 'badarg' exception

Check warning on line 502 in tests/libs/estdlib/test_lists.erl

View workflow job for this annotation

GitHub Actions / build-and-test (gcc-10, ubuntu:20.04, g++-10, -m32 -O3, -DAVM_CREATE_STACKTRACES=off -DAVM_WARNIN...

the call to lists:append/2 will fail with a 'badarg' exception

Check warning on line 502 in tests/libs/estdlib/test_lists.erl

View workflow job for this annotation

GitHub Actions / build-and-test (cc, 28, ubuntu-24.04, c++, 1.17, 3.24.0, -DAVM_DISABLE_JIT=OFF -DAVM_DISABLE_JIT_...

the call to lists:append/2 will fail with a 'badarg' exception

Check warning on line 502 in tests/libs/estdlib/test_lists.erl

View workflow job for this annotation

GitHub Actions / build-and-test (gcc-11, 27)

the call to lists:append/2 will fail with a 'badarg' exception

Check warning on line 502 in tests/libs/estdlib/test_lists.erl

View workflow job for this annotation

GitHub Actions / build-and-test (clang-18, 28)

the call to lists:append/2 will fail with a 'badarg' exception

Check warning on line 502 in tests/libs/estdlib/test_lists.erl

View workflow job for this annotation

GitHub Actions / build-and-test (clang-14, 26)

the call to lists:append/2 will fail with a 'badarg' exception

Check warning on line 502 in tests/libs/estdlib/test_lists.erl

View workflow job for this annotation

GitHub Actions / build-and-test (clang-18, 27)

the call to lists:append/2 will fail with a 'badarg' exception

Check warning on line 502 in tests/libs/estdlib/test_lists.erl

View workflow job for this annotation

GitHub Actions / build-and-test (arm-linux-gnueabihf-gcc, arm-linux-gnueabihf-g++, -mcpu=cortex-a7 -mfloat-abi=har...

the call to lists:append/2 will fail with a 'badarg' exception

Check warning on line 502 in tests/libs/estdlib/test_lists.erl

View workflow job for this annotation

GitHub Actions / build-and-test (cc, 28, ubuntu-24.04, c++, 1.17, 3.24.0, -DAVM_USE_LIBSODIUM=ON, libsodium-dev)

the call to lists:append/2 will fail with a 'badarg' exception

Check warning on line 502 in tests/libs/estdlib/test_lists.erl

View workflow job for this annotation

GitHub Actions / build-and-test (arm-linux-gnueabihf-gcc, 28, ubuntu-24.04, arm-linux-gnueabihf-g++, -mcpu=cortex-...

the call to lists:append/2 will fail with a 'badarg' exception

Check warning on line 502 in tests/libs/estdlib/test_lists.erl

View workflow job for this annotation

GitHub Actions / build-and-test (gcc-13, 26)

the call to lists:append/2 will fail with a 'badarg' exception

Check warning on line 502 in tests/libs/estdlib/test_lists.erl

View workflow job for this annotation

GitHub Actions / build-and-test (arm-linux-gnueabihf-gcc, arm-linux-gnueabihf-g++, -mcpu=cortex-a7 -mfloat-abi=har...

the call to lists:append/2 will fail with a 'badarg' exception

Check warning on line 502 in tests/libs/estdlib/test_lists.erl

View workflow job for this annotation

GitHub Actions / build-and-test (gcc-14, g++-14, gcc-14 g++-14)

the call to lists:append/2 will fail with a 'badarg' exception

Check warning on line 502 in tests/libs/estdlib/test_lists.erl

View workflow job for this annotation

GitHub Actions / build-and-test (gcc-11, 26)

the call to lists:append/2 will fail with a 'badarg' exception

Check warning on line 502 in tests/libs/estdlib/test_lists.erl

View workflow job for this annotation

GitHub Actions / build-and-test (gcc-13, 28)

the call to lists:append/2 will fail with a 'badarg' exception

Check warning on line 502 in tests/libs/estdlib/test_lists.erl

View workflow job for this annotation

GitHub Actions / build-and-test (cc, 26, c++, 1.17)

the call to lists:append/2 will fail with a 'badarg' exception

Check warning on line 502 in tests/libs/estdlib/test_lists.erl

View workflow job for this annotation

GitHub Actions / build-and-test (arm-linux-gnueabihf-gcc, 28, ubuntu-24.04, arm-linux-gnueabihf-g++, -mcpu=cortex-...

the call to lists:append/2 will fail with a 'badarg' exception

Check warning on line 502 in tests/libs/estdlib/test_lists.erl

View workflow job for this annotation

GitHub Actions / build-and-test (cc, c++, -DAVM_CREATE_STACKTRACES=off -DAVM_WARNINGS_ARE_ERRORS=ON)

the call to lists:append/2 will fail with a 'badarg' exception

Check warning on line 502 in tests/libs/estdlib/test_lists.erl

View workflow job for this annotation

GitHub Actions / build-and-test (cc, 27, c++, 1.17)

the call to lists:append/2 will fail with a 'badarg' exception

Check warning on line 502 in tests/libs/estdlib/test_lists.erl

View workflow job for this annotation

GitHub Actions / build-and-test (gcc-8, g++-8, gcc-8 g++-8, ubuntu:20.04)

the call to lists:append/2 will fail with a 'badarg' exception

Check warning on line 502 in tests/libs/estdlib/test_lists.erl

View workflow job for this annotation

GitHub Actions / build-and-test (gcc-11, 28)

the call to lists:append/2 will fail with a 'badarg' exception

Check warning on line 502 in tests/libs/estdlib/test_lists.erl

View workflow job for this annotation

GitHub Actions / build-and-test (clang-16, clang++-16, clang-16)

the call to lists:append/2 will fail with a 'badarg' exception

Check warning on line 502 in tests/libs/estdlib/test_lists.erl

View workflow job for this annotation

GitHub Actions / build-and-test (clang-14, 28)

the call to lists:append/2 will fail with a 'badarg' exception

Check warning on line 502 in tests/libs/estdlib/test_lists.erl

View workflow job for this annotation

GitHub Actions / build-and-test (arm-linux-gnueabihf-gcc, 28, ubuntu-24.04, arm-linux-gnueabihf-g++, -mcpu=cortex-...

the call to lists:append/2 will fail with a 'badarg' exception

Check warning on line 502 in tests/libs/estdlib/test_lists.erl

View workflow job for this annotation

GitHub Actions / build-and-test (gcc-10, g++-10, gcc-10 g++-10)

the call to lists:append/2 will fail with a 'badarg' exception

Check warning on line 502 in tests/libs/estdlib/test_lists.erl

View workflow job for this annotation

GitHub Actions / build-and-test (riscv32-unknown-linux-gnu-gcc, 28, ubuntu-24.04, riscv32-unknown-linux-gnu-g++, -...

the call to lists:append/2 will fail with a 'badarg' exception

Check warning on line 502 in tests/libs/estdlib/test_lists.erl

View workflow job for this annotation

GitHub Actions / build-and-test (xtensa-lx6-linux-gnu-gcc, 28, ubuntu-24.04, xtensa-lx6-linux-gnu-g++, -O2, 1.17, ...

the call to lists:append/2 will fail with a 'badarg' exception

Check warning on line 502 in tests/libs/estdlib/test_lists.erl

View workflow job for this annotation

GitHub Actions / build-and-test (riscv32-unknown-linux-gnu-gcc, ubuntu-24.04, riscv32-unknown-linux-gnu-g++, -DAVM...

the call to lists:append/2 will fail with a 'badarg' exception

Check warning on line 502 in tests/libs/estdlib/test_lists.erl

View workflow job for this annotation

GitHub Actions / build-and-test (clang-15, clang++-15, clang-15)

the call to lists:append/2 will fail with a 'badarg' exception
ok.

test_min() ->
Expand Down
Loading