-
Couldn't load subscription status.
- Fork 3k
Add an array from function #10304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Add an array from function #10304
Conversation
CT Test Results 2 files 97 suites 1h 7m 13s ⏱️ Results for commit 5f8b7c2. ♻️ This comment has been updated with latest results. To speed up review, make sure that you have read Contributing to Erlang/OTP and that all checks pass. See the TESTING and DEVELOPMENT HowTo guides for details about how to run test locally. Artifacts
// Erlang/OTP Github Action Bot |
|
I wonder if it should be called |
Thanks for the suggestion. Discussed this but we think it is fine as it is, the other Other functions that uses a |
To allow array creation from any type of input, for example from binaries without the need to first create a redundant list.
96771ad to
5f8b7c2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds new from/2 and from/3 functions to the array module that create arrays by iteratively calling a function with a state until it returns done. This provides a more flexible way to construct arrays compared to from_list/1.
- Adds
array:from/2andarray:from/3functions to build arrays from a generator function - Includes comprehensive test coverage with
from_test_()and real-world examples inimport_export/1 - Adds doctest integration via
doctests/1test case
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| lib/stdlib/src/array.erl | Implements the from/2 and from/3 functions with documentation and helper functions |
| lib/stdlib/test/array_SUITE.erl | Adds test cases for the new functions including unit tests, integration tests, and doctests |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
|
|
||
| -doc "Equivalent to [`from(Fun, State, undefined)`](`from/3`).". | ||
| -spec from(Function, IntitialState :: S) -> array(Type) when |
Copilot
AI
Oct 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected spelling of 'IntitialState' to 'InitialState'.
| -spec from(Function, IntitialState :: S) -> array(Type) when | |
| -spec from(Function, InitialState :: S) -> array(Type) when |
| See also `new/2`, `from_list/1`, `foldl/3`. | ||
| """. | ||
|
|
||
| -spec from(Function, IntitialState :: S, Default :: term()) -> array(Type) when |
Copilot
AI
Oct 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected spelling of 'IntitialState' to 'InitialState'.
| -spec from(Function, IntitialState :: S, Default :: term()) -> array(Type) when | |
| -spec from(Function, InitialState :: S, Default :: term()) -> array(Type) when |
| done | ||
| end, | ||
|
|
||
| ?_assert(FloatBin =:= array:foldl(ToFloat32, <<>>, array:from(FromFloat32, FloatBin))), |
Copilot
AI
Oct 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The import_export/1 test function returns ok instead of an EUnit test tuple. The ?_assert macros at lines 809 and 819 are evaluated for their side effects but the function returns ok, not a test result. Either change the function to return a list of assertions like [?_assert(...), ?_assert(...)], or use regular true = ... assertions without the ?_ prefix.
To allow array creation from any type of input, for example from binaries without the need to first create a redundant list.