In light of CHatmaker's renewed attention on this post from LinkedIn, I thought I'd piggyback on SergeiBaklan's elegant resolution with some brief combinatory logic. In this method, we still write the main LAMBDA to call itself as an argument, but we then wrap this function in a double-referencing modifier/combinator in order to simplify the input.
=LET(FIX, LAMBDA(f, LAMBDA(x,y, f(f, x, y))),
REPLACECHARS,
FIX(LAMBDA(callSelf,textString,illegalChars,
IF(illegalChars="", textString,
callSelf(callSelf,
SUBSTITUTE(textString, LEFT(illegalChars, 1), ""),
RIGHT(illegalChars, LEN(illegalChars)-1)
)))),
REPLACECHARS("Brian Jones 206", "1234567890")
)
Edit: I've found another way forward that seems to be one step away from a really elegant method. I'm still getting used to combinatory logic, does anyone know how to modify the code below so that we don't have to double-call f(f) in line 8, without specifying the number of arguments for our desired function?
=LET(
REPLACECHARS, LAMBDA(F, F(F))(
LAMBDA(f,
LAMBDA(textString, illegalChars,
IF(
illegalChars = "",
textString,
f(f)(
SUBSTITUTE(textString, LEFT(illegalChars), ),
REPLACE(illegalChars, 1, 1, )
)
)
)
)
),
REPLACECHARS("Brian Jones 206", "1234567890")
)