Skip to content

Conversation

@dgud
Copy link
Contributor

@dgud dgud commented Oct 20, 2025

To allow array creation from any type of input, for example from binaries without the need to first create a redundant list.

@dgud dgud self-assigned this Oct 20, 2025
@dgud dgud added the team:PS Assigned to OTP team PS label Oct 20, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Oct 20, 2025

CT Test Results

    2 files     97 suites   1h 7m 13s ⏱️
2 217 tests 2 165 ✅ 52 💤 0 ❌
2 605 runs  2 549 ✅ 56 💤 0 ❌

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

@bjorng bjorng changed the title Add a array from function Add an array from function Oct 20, 2025
@josevalim
Copy link
Contributor

I wonder if it should be called from_function for consistency with the other from_* functions.

@dgud
Copy link
Contributor Author

dgud commented Oct 23, 2025

I wonder if it should be called from_function for consistency with the other from_* functions.

Thanks for the suggestion.

Discussed this but we think it is fine as it is, the other from_* discuss the input type and here it can take any user specified data
as input.

Other functions that uses a fun like map and fold doesn't specify that it takes a fun as argument.

@dgud dgud added the testing currently being tested, tag is used by OTP internal CI label Oct 24, 2025
To allow array creation from any type of input, for example from
binaries without the need to first create a redundant list.
@dgud dgud force-pushed the dgud/stdlib/array-from/OTP-19815 branch from 96771ad to 5f8b7c2 Compare October 29, 2025 13:51
@dgud dgud requested a review from Copilot October 29, 2025 13:53
Copy link

Copilot AI left a 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/2 and array:from/3 functions to build arrays from a generator function
  • Includes comprehensive test coverage with from_test_() and real-world examples in import_export/1
  • Adds doctest integration via doctests/1 test 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
Copy link

Copilot AI Oct 29, 2025

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'.

Suggested change
-spec from(Function, IntitialState :: S) -> array(Type) when
-spec from(Function, InitialState :: S) -> array(Type) when

Copilot uses AI. Check for mistakes.
See also `new/2`, `from_list/1`, `foldl/3`.
""".

-spec from(Function, IntitialState :: S, Default :: term()) -> array(Type) when
Copy link

Copilot AI Oct 29, 2025

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'.

Suggested change
-spec from(Function, IntitialState :: S, Default :: term()) -> array(Type) when
-spec from(Function, InitialState :: S, Default :: term()) -> array(Type) when

Copilot uses AI. Check for mistakes.
done
end,

?_assert(FloatBin =:= array:foldl(ToFloat32, <<>>, array:from(FromFloat32, FloatBin))),
Copy link

Copilot AI Oct 29, 2025

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.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

team:PS Assigned to OTP team PS testing currently being tested, tag is used by OTP internal CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants