Supercharging for comprehensions

José, I just watched your Twitch stream of day 10 of Advent of Code and, as a fan of for comprehensions, I enjoyed the time you spent discussing potential extensions of them. I recall learning about the reduce option the last time you streamed AoC. I’d like to start a thread to discuss some of those things you discussed. Twitch

I have found myself treating for more like with and sometimes using = in the clauses. My initial thoughts are that it is not a big problem to expect that level of understanding in order to use a group_by or sort_by option. However, I might also be convinced of group_by and sort_by options being a function if they could receive a binding.

I also am intrigued by your suggestion of with. My first thought went to let (allowing multiple of those) in which case they are mutable and the for comprehension can return them as a second binding param.

More thoughts and discussion?

7 Likes

I hesitate to ping you directly because I know you are busy @josevalim but from your day 13 Twitch livestream (Twitch) I see this is still on your mind.

I am in favor of how you have developed the let idea within a for comprehension (and how it can let us deprecate the :reduce option). Like the live chatters in the livestream, I too have a concern about let!/1 so I would prefer that a for that uses let return a 2 element tuple. Is there a benefit of the 2nd element of that tuple being a binding rather than a tuple of the let vars?

2 Likes

Oh, I missed this thread. Yeah, I should submit a proposal by today for for-let. It no longer has let! but retains the rest of the proposal. :slight_smile: thanks for the feedback!

3 Likes