I've heard list comprehension is more optimized that map, reduce etc due to the way it is implemented in Python. Something to do work map, reduce being function calls
As a long time Java developer, I so very much appreciate Streams. It's so much more readable to say "I have a stream of Xs; convert them to Ys, take out the lowercase ones, add them to a Set, and return it" than "create a new Set. Now iterate through all the Xs. Declare a variable of type Y. Now set it to the conversion result of X. If Y is lowercase, add it to the set. Now return the set."
And that's a simple example. Once you start dealing with Lists of Lists, things go off the rails so quickly and the nesting becomes so ugly.
That’s interesting to read, as a beginner I find them very confusing and think it’s much simpler to do one thing after another, especially once it comes to looking for bugs.
Yeah, I can understand that. Streams add another layer of abstraction that requires understanding the core behaviors first. Streams are basically shortcuts for longer blocks of code, and they're easier to compose but can be harder to debug if you're not certain about what's happening under the hood. They provide incredible flexibility and conciseness, which is why they're so useful.
Just wait until you start getting into RX. Even once you get the hang of Java Streams, RX is going to make you so confused and frustrated that you're going to want to give up, but sticking with it is so worth it in the end. I'd recommend waiting a few years before even looking into RX though.
Learn Haskell! We have general monad comprehensions. Lists, IO, parser combinators—as long as it's a monad, we have comprehensions for it. And sometimes even comprehensions for non-monads with ApplicativeDo.
Heck, I wrote a brainfuck interpreter comprehension not too long ago.
413
u/[deleted] Aug 26 '20
Started learning python and thats my favourite thing after no ; thingy