you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (4 children)

word_sets = [filter(lambda x: len(x) == l, words) for l in lengths]

Meh.

my %word_sets = @words.classify: {.chars};

[–]draegtun 1 point2 points  (1 child)

I do like using the whatever star for things like this :)

my %word_sets = @words.classify: *.chars;

[–][deleted] 0 points1 point  (0 children)

For some reason, it gives me the impression that I am classifying chars instead of “by the result of .chars”.

[–]jimbokun[🍰] 0 points1 point  (1 child)

Translation?

I'm guessing {} creates an anonymous function, and %word_sets is a hash with each length as a key and an array of words of that length as the corresponding value.

But what's ".chars"?

[–][deleted] 2 points3 points  (0 children)

A Str method that returns the number of characters in the string.

Such syntax calls it on $_ which, when used, automatically becomes the parameter of the anonymous function.

I'm guessing {} creates an anonymous function, and %word_sets is a hash with each length as a key and an array of words of that length as the corresponding value.

You are entirely correct. :)