RosettaCodeData/Task/Catamorphism/Excel/catamorphism.excel

85 lines
1.2 KiB
Plaintext

FOLDROW
=LAMBDA(op,
LAMBDA(a,
LAMBDA(xs,
LET(
b, op(a)(HEADROW(xs)),
IF(1 < COLUMNS(xs),
FOLDROW(op)(b)(
TAILROW(xs)
),
b
)
)
)
)
)
updatedBracketDepth
=LAMBDA(depth,
LAMBDA(c,
IF(0 <= depth,
IF("[" = c,
1 + depth,
IF("]" = c,
depth - 1,
depth
)
),
depth
)
)
)
bracketCount
=LAMBDA(a,
LAMBDA(c,
IF(ISNUMBER(FIND(c, "[]", 1)),
1 + a,
a
)
)
)
HEADROW
=LAMBDA(xs,
LET(REM, "The first item of each row in xs",
INDEX(
xs,
SEQUENCE(ROWS(xs)),
SEQUENCE(1, 1)
)
)
)
TAILROW
=LAMBDA(xs,
LET(REM,"The tail of each row in the grid",
n, COLUMNS(xs) - 1,
IF(0 < n,
INDEX(
xs,
SEQUENCE(ROWS(xs), 1, 1, 1),
SEQUENCE(1, n, 2, 1)
),
NA()
)
)
)
CHARSROW
=LAMBDA(s,
MID(s,
SEQUENCE(1, LEN(s), 1, 1),
1
)
)