Still writing for loops user?

Still writing for loops user?

Attached: how to use forEach in Java 8.jpg (1276x958, 77K)

Other urls found in this thread:

doc.rust-lang.org/std/iter/trait.Iterator.html#method.any
blog.jooq.org/2015/12/08/3-reasons-why-you-shouldnt-replace-your-for-loops-by-stream-foreach/
twitter.com/NSFWRedditVideo

Tell me what this accomplishes, like i’m 5.

>List = Arrays.asList()
>.stream()
>System.out.println
Java is a disease

ParameterizedStreetShittingLanguageHandlerInvocationService

this isnt reddit retard

This is a nice feature, but I've written code like this in production and most recent grads can't handle it. Or someone comes in and it confuses the hell out of them.

Delete this failure of a post you .foreach'ing retard.

>java lambdas

They're slow as hell.

I don't know if it's the implementation of how they are used in a JVM or anything, but for small instances like 1-100, the overhead of invoking it is way more expensive than just using a simple loop. The JVM probably also isn't doing loop unrolling and all the fancy stuff that we have for loops by now.

This. In C++ or something it can be fast, but you still pay in compile times, bad debug performance, heavier debug symbols, and worse stack traces. So yeah, I'm feeling kind of skeptical of this stuff these days and have kinda tried to go back to dumb loops.

CPUs have stopped getting faster, but the software (as evidenced by this monstrosity) sure as heck is getting slower...

In Haskell this is just sequence_ $ print filter even [1..6]

This. I work with people who swear by using this shit fucking everywhere and they really just don't get that this level of convenience comes at a cost.

How? You just read the method name.

If anyone says streams are more confusing than procedural they are retards who just memorised code without understanding it.

By definition declarative is more readable.

in haskell this is just
traverse_ print . filter even

Ah, so traverse_ is just fmap followed by sequence? now it makes sense.

>By definition declarative is more readable.
You apparently don't know what "by definition", "declarative" and "more readable" mean...

Because they only taught Java in uni and omitted functional programming entirely. All you have to do is work with it for a bit and it becomes second nature after awhile though, same as most unfamiliar things

traverse is "an effectful map"
you walk over a structure, possibly producing some effect along the way, and traverse gives you back an effect that will produce the entire structure, after you've walked over it
basically mapM but generalised for Foldables

Arrays.asList(1,null,2,3);

nah I exclusively use tail recursion to make Sussman happy

Meanwhile in Rust pretty much every collection can be turned into iterator which acts like Stream, Iterator, IntStream, PrimitiveIterator and all other Java sheningans and can be implemented with just one method.

doc.rust-lang.org/std/iter/trait.Iterator.html#method.any

Attached: 1563959638999_0.png (600x600, 249K)

And then you come into production and cannot write any streams because they cannot be hotcode replaced. Also half of people that you work with are POO boomers.
Nice feature though

Attached: me.png (225x225, 10K)

Five years old you say?

Attached: 1565192846657.png (693x601, 259K)

.foreach(i -> System.out.println(i));

Can be replaced with a method reference:
.foreach(System.out::println);

>::
god java is disgusting

hey Jow Forums why are languages forcing this non-loop semantics onto their users?
c# linq
java streams
c++ ranges

and all the new languages also follow this, rust kotlin etc

because it's better than writing loops

Not this fucking thread again

>just because
lol hows life as an npc?

It's better in a while variety of ways, but perhaps most importantly it makes your code easier to compose, and allows abstractions to be built around things that would be awkward with normal loops. Ie, with streams / iterators and chaining notation, you can easily return another stream / iterator with some transformations applied, and have other code re-use your redundant transformations.

You can do that in many languages.

>just because
no they're better because they're more declarative, more composable and less error prone you procedural brainlet

:: in Java particularly is a backward compatibility hack.

what? wouldn't it be more efficient to loop once to filter and do the foreach operation. I'm sure for small arrays it wouldn't make a difference but if you're dealing with some huge ass array why bother iterating twice.

it's not iterating twice you mong

how do you think the filter works?

Java streams are less efficient but that's not why. They're lazy, the whole thing only gets computed when you call collect.

they aren't forcing you to do anything

Attached: linq to the past.png (349x56, 3K)

blog.jooq.org/2015/12/08/3-reasons-why-you-shouldnt-replace-your-for-loops-by-stream-foreach/

/thread

Based lintposter

Just reach out to native handcoded assembly NO FOR

Rust iterators are one of its underrated comfy features

It's being lazily evaluated.

This is nothing new. Non FP nerds finally found out about this stuff and flocked to multi-paradigm languages where it was already possible and the industry titans had to react. I've been using this style in Perl ever since I realized plain old loops aren't always the most convenient way to get things done.