Forum Discussion
Array of arrays using Lambda helper functions
- Aug 11, 2021
PeterBartholomew1Just to get rid of that pesky blank row:
=REDUCE( "", ListCountry#, LAMBDA(acc,val, IF( TYPE(acc)<>64,TRANSPOSE(FILTER(StartList[ATHLETE],StartList[COUNTRY]=val)), VSTACKλ(,acc,TRANSPOSE(FILTER(StartList[ATHLETE],StartList[COUNTRY]=val))) ) ) )
I think since MAP will iterate over an array of any shape, the results have to fit back into the same shape; I'd be interested to know if this is a mistaken assumption on my part.
I was looking for a later post but, since this one turned up, your more recent strategy using Thunks appears to be relevant for the sorted list of lists problem.
= LET(
THUNKλ, LAMBDA(x, LAMBDA(x)),
EXPANDλ, LAMBDA(ϑ, LAMBDA(r,c, INDEX(INDEX(ϑ,r,1)(),c))),
m, ROWS(ListCountry#),
n, MAX(COUNTIFS(StartList[COUNTRY],ListCountry#)),
resultϑ, MAP(ListCountry#,
LAMBDA(country, THUNKλ(FILTER(StartList[ATHLETE], StartList[COUNTRY]=country)))),
display, MAKEARRAY(m,n, EXPANDλ(resultϑ)),
IFERROR(display,""))
I have a nasty feeling that such techniques are not for the fainthearted! Teaching the approach could be challenging as well.
- tbouldenJan 15, 2022Iron ContributorSorry for the delay! I like this approach, had to refresh my memory on what territory we traversed in this thread.
I agree about teaching to others, have been conversing with someone on a forum asking "why use thunks?" and asking for simple examples. I may have to show them this as it may be more accessible way of demonstrating. Hope 2022 has started off well for you!- PeterBartholomew1Jan 15, 2022Silver Contributor
It was the fact that I do not find picking up on some of our past discussions to be a trivial exercise that made me think of how one might train others. The challenge might be almost as significant as setting out to move an Excel user to M or DAX. Whilst one may argue that Lambda functions are simple extensions of the traditional spreadsheet methods to include user-defined functions, the process of solution development shifts from the ad-hoc to being a programming exercise (by way of contrast, traditional methods allow users to interact with their numbers whilst remaining in denial that they are actually programming).
I am happy that you should modify or use the example as you see fit and I would be interested to know whether you convince your forum member.