Last active
March 15, 2026 06:42
-
-
Save Medohh2120/d9d04f56d93694aed9d0c49d516f0fbf to your computer and use it in GitHub Desktop.
Versions of BYROW, BYCOL, MAP that can return nested arrays
This file contains hidden or 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
| /* | |
| Name: BYROW⊟ | |
| Description: A high-performance version of BYROW that supports "Array of Arrays" (nested results). | |
| [orient] logic to control the assembly of results: | |
| (0) or Omitted: (Stacks each row result vertically). | |
| (1) : (Stacks each row result horizontally). | |
| Made By: Medohh2120 | |
| */ | |
| BYROW⊟ = LAMBDA(array, function, [orient], | |
| LET( | |
| indices, SEQUENCE(ROWS(array)), | |
| orient, IF(orient, HSTACK, VSTACK), | |
| me, LAMBDA(me, segment, | |
| LET( | |
| n, ROWS(segment), | |
| IF( | |
| n = 1, | |
| function(INDEX(array, @segment, 0)), | |
| orient(me(me, TAKE(segment, INT(n / 2))), me(me, DROP(segment, INT(n / 2)))) | |
| ) | |
| ) | |
| ), | |
| IFERROR(me(me, indices), "") | |
| ) | |
| ); | |
| /* | |
| Name: MAP⊞ | |
| Description: A high-performance version of MAP that supports "Array of Arrays" (nested results). | |
| [orient] logic to control the assembly of results: | |
| (0) or Omitted: (Maintains the input grid's relative positioning). | |
| (1): Stacks each cell result vertically. | |
| (2): Stacks each cell result horizontally. | |
| Made By: Medohh2120 | |
| */ | |
| MAP⊞ = LAMBDA(array, function, [orient], | |
| LET( | |
| is_vert, ROWS(array) >= COLUMNS(array), | |
| v_glue, IF(orient = 2, HSTACK, VSTACK), | |
| h_glue, IF(orient = 1, VSTACK, HSTACK), | |
| me, LAMBDA(me, segment, | |
| LET( | |
| r, ROWS(segment), | |
| c, COLUMNS(segment), | |
| IF( | |
| r * c = 1, | |
| function(@segment), | |
| IF( | |
| is_vert, | |
| IF( | |
| r > 1, | |
| v_glue(me(me, TAKE(segment, INT(r / 2))), me(me, DROP(segment, INT(r / 2)))), | |
| h_glue(me(me, TAKE(segment, , INT(c / 2))), me(me, DROP(segment, , INT(c / 2)))) | |
| ), | |
| IF( | |
| c > 1, | |
| h_glue(me(me, TAKE(segment, , INT(c / 2))), me(me, DROP(segment, , INT(c / 2)))), | |
| v_glue(me(me, TAKE(segment, INT(r / 2))), me(me, DROP(segment, INT(r / 2)))) | |
| ) | |
| ) | |
| ) | |
| ) | |
| ), | |
| IFERROR(me(me, array), "") | |
| ) | |
| ); | |
| /* | |
| Name: BYCOL▥ | |
| Description: A high-performance version of BYCOL that supports "Array of Arrays" (nested results). | |
| [orient] logic to control the assembly of results: | |
| (0) or Omitted: Stacks every result horizontally. | |
| (1): Stacks every result vertically. | |
| Made By: Medohh2120 | |
| */ | |
| BYCOL▥ = LAMBDA(array, function, [orient], | |
| LET( | |
| indices, SEQUENCE(, COLUMNS(array)), | |
| orient, IF(orient, VSTACK, HSTACK), | |
| me, LAMBDA(me, segment, | |
| LET( | |
| n, COLUMNS(segment), | |
| IF( | |
| n = 1, | |
| function(INDEX(array, 0, @segment)), | |
| orient(me(me, TAKE(segment, , INT(n / 2))), me(me, DROP(segment, , INT(n / 2)))) | |
| ) | |
| ) | |
| ), | |
| IFERROR(me(me, indices), "") | |
| ) | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment