-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 Signed-off-by: migmatore <[email protected]>
- Loading branch information
Showing
3 changed files
with
33 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
% Copyright 2017-2023 Fred Dushin <[email protected]> | ||
% split/2 function Copyright Ericsson AB 1996-2023. | ||
% keytake/3 function Copyright Ericsson AB 1996-2024. | ||
% append/1 function Copyright Ericsson AB 1996-2025. | ||
% | ||
% Licensed under the Apache License, Version 2.0 (the "License"); | ||
% you may not use this file except in compliance with the License. | ||
|
@@ -60,7 +61,8 @@ | |
split/2, | ||
usort/1, usort/2, | ||
duplicate/2, | ||
sublist/2 | ||
sublist/2, | ||
append/1 | ||
]). | ||
|
||
%%----------------------------------------------------------------------------- | ||
|
@@ -758,3 +760,20 @@ sublist(List, Len) when is_integer(Len) andalso Len >= 0 -> | |
sublist0([], _Len) -> []; | ||
sublist0(_, 0) -> []; | ||
sublist0([H | Tail], Len) -> [H | sublist0(Tail, Len - 1)]. | ||
|
||
%%----------------------------------------------------------------------------- | ||
%% @param ListOfLists a list of lists to make the general list from | ||
%% @returns a list made of the sublists of `ListOfLists`. | ||
%% @doc Returns a list in which all the sublists of `ListOfLists` have been appended. | ||
%% @end | ||
%%----------------------------------------------------------------------------- | ||
%% Attribution: https://github.com/erlang/otp/blob/35037ba900e15bd98e778e567079b426531d0085/lib/stdlib/src/lists.erl#L202 | ||
-spec append(ListOfLists) -> List1 when | ||
ListOfLists :: [List], | ||
List :: [T], | ||
List1 :: [T], | ||
T :: term(). | ||
|
||
append([E]) -> E; | ||
append([H | T]) -> H ++ append(T); | ||
append([]) -> []. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
% This file is part of AtomVM. | ||
% | ||
% Copyright 2019-2021 Fred Dushin <[email protected]> | ||
% Copyright 2025 migmatore <[email protected]> | ||
% | ||
% Licensed under the Apache License, Version 2.0 (the "License"); | ||
% you may not use this file except in compliance with the License. | ||
|
@@ -49,6 +50,7 @@ test() -> | |
ok = test_filtermap(), | ||
ok = test_last(), | ||
ok = test_mapfoldl(), | ||
ok = test_append(), | ||
ok. | ||
|
||
test_nth() -> | ||
|
@@ -321,4 +323,14 @@ test_mapfoldl() -> | |
?ASSERT_ERROR(lists:mapfoldl(fun(X, A) -> {X * A, A + 1} end, 1, foo), function_clause), | ||
ok. | ||
|
||
test_append() -> | ||
?ASSERT_MATCH(lists:append([]), []), | ||
?ASSERT_MATCH(lists:append([[1, 2, 3, 4]]), [1, 2, 3, 4]), | ||
?ASSERT_MATCH(lists:append([[1, 2], [3, 4]]), [1, 2, 3, 4]), | ||
?ASSERT_MATCH(lists:append([[1, 2], [a, b]]), [1, 2, a, b]), | ||
?ASSERT_MATCH(lists:append([["1", "2"], [a, b]]), [1, 2, a, b]), | ||
?ASSERT_ERROR(lists:append(1), function_clause), | ||
?ASSERT_ERROR(lists:append(1, 3), function_clause), | ||
ok. | ||
|
||
id(X) -> X. |