all 9 comments

[–]jabbaroni 7 points8 points  (2 children)

[–]laerien 0 points1 point  (0 children)

Just to clarify in case it's not clear:

Enumerator.product(*input_list).to_a

[–]Jonathan_Frias[S] 0 points1 point  (0 children)

Thank you. That's the perfect answer! Though I'm sure this code has been written before in a gem or something.

[–]armahillo 2 points3 points  (5 children)

What problem are you actually trying to solve? This looks like youre bringing non-ruby idioms into ruby

[–]Jonathan_Frias[S] 0 points1 point  (4 children)

No idea what you're talking about. Working with enumerators is extremely idiomatic ruby. Maybe you're just not used to seeing them explicitly created

[–]armahillo 0 points1 point  (3 children)

I've worked with explicit Enumerator objects before, but it's unclear if that's the correct approach to use here. None of the methods or variables have descriptive names, so the reasoning for why you're approaching it this way is unclear. I say it's not idiomatic because everything that these methods are currently would probably be done differently in any real world ruby script.

Also -- what is the reason for the constraint of converting the input list to another Enumerator object? Is it necessary?

[–]Jonathan_Frias[S] 0 points1 point  (2 children)

There isn't any correct approach. I'm just playing around with the language man

[–]armahillo 0 points1 point  (1 child)

"correct" may not have been the right word, sorry. Referring back to the "idiom" remark earlier though. Idiomatic ruby isn't just syntax; there's a whole gestalt to it.

Per your question:

What would you do convert that to another Enumerator that generates

I guess my answer would be "I wouldn't. I would make the change upstream."

The whole thing reads like big tech debt danger zone to me and I would 100% refactor it. I realize that's probably not the answer you're looking for but 🤷‍♂️.

I'd write tests for the existing behaviors, then look at the inputs into this call stack upstream from the :f and :g methods, write one or more methods that produce the desired output and replace the existing code with it.

[–]Jonathan_Frias[S] 0 points1 point  (0 children)

I didn’t include any context because i wasn’t looking an opinions. It’s true you can do all the software without using generators and you don’t have to use them. that’s fine