Skip to content

Add array @reduce, @filter, @any, @all, & @indices_of#2419

Merged
lerno merged 12 commits into
c3lang:masterfrom
NotsoanoNimus:array-fold
Aug 25, 2025
Merged

Add array @reduce, @filter, @any, @all, & @indices_of#2419
lerno merged 12 commits into
c3lang:masterfrom
NotsoanoNimus:array-fold

Conversation

@NotsoanoNimus
Copy link
Copy Markdown
Contributor

Add another wave of new core array operations to the standard library.

In brief:

  1. @reduce - apply a function iteratively to an array and store the result into an accumulator.
    a. @sum - terse way to sum up all array elements with @reduce.
    b. @product - terse way to multiply all array elements with @reduce.
  2. @filter - creates a shallow copy of an array, containing only copies of elements which match a given predicate function.
  3. @any - return true when any element in the array matches a given predicate function.
  4. @all - return true when all elements in the array match a given predicate function.
  5. @indices_of - underlies the @filter macro; returns the indexes of the array which match the given predicate function.

Please see the test/unit/stdlib/core/array.c3 file for a detailed look at each function's unit testing. Also, these functions (like @zip ones) are compatible with List types and other iterables.

@lerno lerno merged commit 410a25f into c3lang:master Aug 25, 2025
42 of 43 checks passed
@lerno
Copy link
Copy Markdown
Collaborator

lerno commented Aug 25, 2025

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants