S
Sebastian
Am 16.06.2013 00:18, schrieb markspace:
many tasks that work on streams can be parallelized by just calling the
parallel() method on the stream. That's explicit but unobtrusive - all
the concurrent stuff happens under the hood (based on the
fork-join-framework of Java 7). I haven't yet looked at this in detail,
though.
[snip]
that's good to see. Thanks for sharing the code. It's nice having a real
sieve of Eratosthenes now. (But I still like the simple formulation of
the naive algorithm, just for its looks - although objectively it
performs worse.)
I also like your step-by-step exposition.
Best Regards,
Sebastian
yes, I think its a good thing this is being added to Java. A real advance.Am 11.06.2013 23:27, schrieb Sebastian:
[snip]I have thought again, and will put something together on a blog. May
take a day or two, I'll be back to post a link. It will still be hard
to follow, though. Meanwhile, a good place to get started with the topic
would be Maurice Naftalin's Lambda FAQ at http://www.lambdafaq.org/
-- Sebastian
I have written two blog entries about higher-order functions with Java 8
lambda expressions. They can be found at
http://sebastian-millies.blogspot.de/
So I had a chance to look at this a bit. Lambda are kind of cool. You
can generate lists of number easily:
static void test1() {
Stream.iterate( 0, x -> x + 1 )
;
}
yes, that's how it works. By the way, streams are not only lazy, butThis actually runs, even though the list is infinite. Many streams are
lazy, and don't evaluate unless asked for more. I guess the stream above
initializes its values, but then never generates any numbers since it's
never asked for any.
many tasks that work on streams can be parallelized by just calling the
parallel() method on the stream. That's explicit but unobtrusive - all
the concurrent stuff happens under the hood (based on the
fork-join-framework of Java 7). I haven't yet looked at this in detail,
though.
[snip]
[snip]So to make this print primes, we have to filter a little differently. I
really didn't understand the code in your first post, so I might be
missing some points here. But I followed the example that you linked to
earlier:
Cf. this paper by Melissa E. O’Neil:
http://www.cs.hmc.edu/~oneill/papers/Sieve-JFP.pdf
And I gave that a go. The trick is to define your own predicate. No,
it's not really a lambda at that point, but it does work, and with less
code than either your first example or your blog. (Although barely less.)
that's good to see. Thanks for sharing the code. It's nice having a real
sieve of Eratosthenes now. (But I still like the simple formulation of
the naive algorithm, just for its looks - although objectively it
performs worse.)
I also like your step-by-step exposition.
Best Regards,
Sebastian