@Adám Basically all the Phase 2 competition problems have obvious domain generalizations which can be expressed concisely with Rank and Depth. Generally, though, the one I have been bumping into most often lately is making functions agnostic to a particular presentation of text data: character vector with newlines, vs vector of line strings, vs character matrix.
> Given a non-empty character vector of single-letter grades ABCDF, produce a 3-column, 5-row, alphabetically-sorted matrix of each grade, the number of occurrences of that grade, and the percentage (rounded to 1 decimal position) of the total number of occurrences of that grade. The table should have a row for each grade even if there are no occurrences of a grade.
I failed to solve this one in APL style. I did not succeed to take into account the grades which were not present (as in example 2 or 3). Also sorting was difficult. Or can you use an axis of the matrix to sort on?
I have a proposal to use the operand as vocabulary (and then use {⊂⍵} as actual operand to Key). With that, we'd have just 'ABCDF'∘{⍺,c,⍪10÷⍨⌊0.5+1000×(c←≢¨⍺⌸⍵)÷≢⍵}
If I could start over, I'd make ⌸ a dyadic operator, taking a vocabulary as right operand, but allowing a function to compute the vocabulary too. Then current f⌸ would be f⌸∪.
Btw, my solutions were 'ABCDF'∘{s←+/⍺∘.=⍵ ⋄ ⍺,s,⍪⍎1⍕100×s÷≢⍵} and 'ABCDF'∘{s←+/⍺∘.=⍵ ⋄ ⍺,s,⍪10÷⍨⌊0.5+1000×s÷≢⍵}
@Richard That's exactly my proposal. But I wouldn't call the left operand useless. Yes, you can always use f¨{⊂⍵}⌸ but some common operands can be optimised and avoid the intermediary (potentially expensive to compute and represent) nested value.
@Adám I was a little surprised how much faster this was over using Key, but with such a small vocabulary I guess it is expected. Did some testing (my laptop, 1e7≥≢⍵) and it seems like +/⍺∘.=⍵ is faster than ¯1+{≢⍵}⌸⍺,⍵ for vocabularies up to length 8, after that Key is faster.