Forum Discussion
BigSpill: A 90‑Function Excel LAMBDA Library for Dynamic Arrays
Pairwiseλ is my approach to generating a Cartesian product of 2 sets. Here is a demo with a deck of cards created from rank and suit.
The function is written as simply as possible. The goal was to make it fast, efficient, and predictable.
/* [GR06] -------------------------------------------------------------------------
Function: Pairwiseλ
Category: Grid Analytics (Categorical Analysis)
Author: Patrick H.
Version: 1.1
Dependencies: Echoλ, Resizeλ
Description:
Creates vertical pairs from 1D and scalar inputs. Inputs are flattened with
TOCOL to normalize orientation. 2D arrays are strictly prohibited.
Parameters:
vector_1 - 1D vector or scalar.
vector_2 - 1D vector or scalar.
------------------------------------------------------------------------------*/
Pairwiseλ=
LAMBDA(
vector_1,
vector_2,
LET(
// Flatten inputs
v, TOCOL(vector_1),
v₂, TOCOL(vector_2),
// Element counts
k, COUNTA(v),
k₂, COUNTA(v₂),
// Halting scenarios
Is2DInput?, OR(AND(ROWS(vector_1)>1, COLUMNS(vector_1)>1),
AND(ROWS(vector_2)>1, COLUMNS(vector_2)>1)),
Is2Big?, k * k₂ > 1000000,
IF(Is2DInput?, #VALUE!,
IF(Is2Big?, #NUM!,
LET(
// Cartesian expansion
x, Echoλ(v, k₂),
y, Resizeλ(v₂, k),
pairs, HSTACK(x, y),
pairs
)))));
I have two more functions in the pipeline for the next update:
Triplewiseλ - Cartesian product of 3 sets
Quadwiseλ - Cartesian product of 4 sets
These two are of note because they provide an elegant way to generate indices. I'm toying with Windowedλ which extracts overlapping windows (n x n) from a 2D grid in row-major/col-major order. All will be in the next update.
- m_tarlerSep 01, 2026Silver Contributor
Hi Patrick2788 , as always I enjoy seeing what you have created. In light of the above and the comment about going to triple and quad I thought of an alternative to your Pairwise that can handle ROWS so you can just call it multiple times as needed:
PairRowsλ= LAMBDA( vector_1, vector_2, LET( // Element counts k, ROWS(vector_1), k₂, ROWS(vector_2), Size, k * k₂, IF(Size > 1000000, #NUM!, LET( // Cartesian expansion x, CHOOSEROWS(vector_1, INT(SEQUENCE(Size,,0)/k₂)+1), y, CHOOSEROWS(vector_2, MOD(SEQUENCE(Size,,0),k₂)+1), pairs, HSTACK(x, y), pairs ))));So instead of being limited to a single column to get repeated it will pair full rows. Here is an example from your sample sheet where I added Toppings to your icecream...