Curious about the future of data-driven systems? Join our Data Engineering roundtable and learn how to build scalable data platforms.
Data Engineering: The industry has come a long way from organizing unstructured data to adopting today's modern data pipelines. See how.
Stats
| Reputation: | 1485 |
| Pageviews: | 641.8K |
| Articles: | 12 |
| Comments: | 16 |
Comments
May 04, 2019 · Lindsay Burk
Sure, I will gladly add clarification to remove the ambiguity, thanks!
May 03, 2019 · Lindsay Burk
Thanks, that's a nice idea! It's short and nice but it won't propagate exceptions properly and will cause the thread to get blocked forever waiting for LinkedBlockingQueue::take to return a result
Yes, I used this approach myself in the library mentioned in the article - it's perfectly possible, but still most cases will involve them getting completed by some background threads. Waiting for the Project Loom to change it
Apr 19, 2019 · Naveen Yalla
JdbcTemplate serves the purpose really well, though
Mar 14, 2019 · Duncan Brown
Oh, that's a very good point - will fix :)
Mar 14, 2019 · Duncan Brown
It's deliberate - the empty case is not supported and rejected before even gets to the spliterator. There's no need to create the object if we don't need it at all. If we don't use it to handle empty cases, then no need to check this as well in tryAdvance
Sep 21, 2018 · Duncan Brown
groupingBy is way more expensive - if your use case can be solved using filter() only, definitely go for it
Sep 21, 2018 · Duncan Brown
Thanks for the suggestion, David. One question, though - are you familiar with how the reduce operation works on sequences? the article was supposed to be a high-level overview of groupingBy capabilities, that would be probably an overkill to explain the semantics of each operation not in the context of groupingBy usages
Sep 19, 2018 · Duncan Brown
If I got you right, you don't need groupingBy() for this, you can simply use partitioningBy():
Map<Boolean, List<String>> result = Stream.of("abc", "def")
.collect(Collectors.partitioningBy(s -> s.startsWith("a")));
System.out.println(result); // {false=[def], true=[abc]}
Aug 23, 2018 · Duncan Brown
I've been wondering the same, even dedicated a section to it here:
https://4comprehension.com/java-8-the-bad-parts/
Jul 28, 2018 · Duncan Brown
In such case, I'd advise being explicit about the optionality of the result by returning an Optional instance, but it's a good point and I will it to the article, thanks :) I like the idea with freeing the supplier as well!
Oct 04, 2017 · Grzegorz Piwowarek
Martin, I'm not sure if I fully understand - can you elaborate, please?
It does not matter to what it compiles at this point. Provided functional interfaces miss the "throws Something" which simply does not compile if a checked exception is thrown inside
Sep 29, 2017 · Mike Gates
I just tried it - there are no shortcuts for .collect(Collectors.toXXX), unfortunately
Sep 21, 2017 · Grzegorz Piwowarek
The pragmatic reason for including the second solution is the fact that if that was omitted it'd immediately spark questions "Why not just sort the Stream instance?"
As long as API provides an iterator, it's fine to use Streams there - can't discuss with personal preference, though
Sep 20, 2017 · Grzegorz Piwowarek
Well, obviously we do not need to consume all elements at once. With Stream API, we can easily reach, let's say, first N elements + apply some processing on top of them - that's much handier than polling elements in a loop.
Sep 18, 2017 · Grzegorz Piwowarek
At the end of the day, you need to reach all accumulated elements to do something with them, right?
This is where it'd be nice to have something better than a for-loop
Sep 18, 2017 · Grzegorz Piwowarek
Good point - I will add some additional clarification there.
I will add also a Java 9 section in there.