Questions tagged [streamex]

StreamEx a library enhancing Java Streams. Use this tag for questions about specific usage of this library.

StreamEx a library enhancing Java Streams.

15 questions
16
votes
5 answers

Collect pairs from a stream

I have a stream of objects like this: "0", "1", "2", "3", "4", "5", How can I transform it to stream of pairs : { new Pair("0", "1"), new Pair("2", "3"), new Pair("4", "5")}. The stream size is unknown. I am reading data from a file that might…
niemar
  • 612
  • 1
  • 7
  • 16
9
votes
1 answer

How do I sum the double values of a map stream in streamex?

The StreamEx library seems to really help me write Java 8 streams concisely, especially when considering maps (using mapKeyValue, for example, instead of having to unbox the map entries manually). If I have a stream of entries in a map, in vanilla…
Graeme Moss
  • 7,995
  • 4
  • 29
  • 42
8
votes
2 answers

StreamEx.parallel().forEach() does not run in parallel after .map()

I noticed that if I use StreamEx lib to parallel out my streams with a custom ForkJoinPool as below - the subsequent actions do run in parallel threads from that pool. However, if I add a map() operation and parallel the resulting stream - only one…
Marina
  • 3,894
  • 9
  • 34
  • 41
3
votes
1 answer

Why StreamEx force me to add "? extends" to variable type when collecting to list?

I noticed that in the case below standard Java stream better "calculate" variable type than StreamEx. This is odd, because people love StreamEx and use it everywhere, but then code become polluted with "?". I want to use List but StreamEx…
Oleg Vazhnev
  • 23,239
  • 54
  • 171
  • 305
3
votes
2 answers

Remove empty Optionals from Stream using StreamEx

I'm searching for an elegant way to stream only non-empty Optional entries using the StreamEx library. Or the standard library, if it's possible. Currently I'm using the following, rather verbose, approach: List> list = …
Henrik Aasted Sørensen
  • 6,966
  • 11
  • 51
  • 60
3
votes
1 answer

Should StreamEx parallelism work when using takeWhile?

I have a stream that I create like this: StreamEx.generate(new MySupplier>()) .flatMap(List::stream) .map(Entity::getName) .map(name -> ...) .. // more stuff I can change this to work in parallel by just…
Johan
  • 37,479
  • 32
  • 149
  • 237
3
votes
1 answer

How to unwrap StreamEx to a "Plain Old Java Stream"?

StreamEx is a powerfull library but at some point I don't need its superpowers anymore. How could I get rid of StreamEx internal overhead ? Could this pose a problem ? Ex. public void process(Path path){ StreamEx.of(Files.lines(path)) …
Cerber
  • 2,889
  • 4
  • 27
  • 43
2
votes
2 answers

Stream groupingBy values

Is there a non-terminal version of groupingBy or some other neat way to stream through the resulting Map entries/values? I find myself wanting to stream through the values after groupingBy but the best I could come up with is not pretty: …
rednoah
  • 1,053
  • 14
  • 41
1
vote
1 answer

Merge a List of pojos into a Map of integers that can be combined on a key

I am trying to stream-ify the following logic: I have a map of Integer ids to an integer count. I have a list of Pojos that represent the ids. I want to merge the two and have a map of pojos to integer count. Currently I have: return…
Anthony
  • 189
  • 1
  • 15
1
vote
4 answers

StreamEx grouping into lists returns an incorrect number of records

The following code splits a stream of objects into chunks of 1000, processes them on materialisation and returns the total number of objects at the end. In all cases the number returned is correct unless the stream size happens to be 1. In the case…
wild_nothing
  • 2,845
  • 1
  • 35
  • 47
1
vote
1 answer

Eclipse External Null Annotation for AbstractStreamEx.nonNull()

Consider the following example code. This code uses Eclipse's @NonNull and @Nullable annotations to check for nulls. Unfortunately, Eclipse flags an error on the line map(toNonNull). import java.util.function.Function; import…
Nathan
  • 8,093
  • 8
  • 50
  • 76
0
votes
1 answer

How to print streamex on the console

i try to print all elements of the streamex on the console, but I get always this issue one.util.streamex.StreamEx@2e817b38 So I call "convert" method from the main, but i doesn't work.. Do you have any idea, how can I make it right? I hope to get…
Berder
  • 1
0
votes
1 answer

Java stream and groupping: put object to multiple groups

I don't think, that it's called "groupping" but I need to achive the following: I have class class Person { String name; Set groups; } I have some persons: Father => {"Worker", "Men"} Mother => {"Woman"} Son => {"Student","Men"}…
EvilOrange
  • 876
  • 1
  • 9
  • 17
0
votes
1 answer

Add a Method to Java 8 Stream

While working with Java 8 Streams, I some times find that Stream doesn't have a particular method that I desire (e.g. takeWhile(), dropWhile(), skipLast()). How do I create my own stream class which has the additional methods with out re-writing…
Nathan
  • 8,093
  • 8
  • 50
  • 76
-1
votes
1 answer

Create a Map with SimpleEntry and StreamEx

I saw an example of StreamEx wich is quite nice and which goes like this Map toMap = StreamEx.of(splittedTimeUnit1) .pairMap((s1, s2) -> s1.matches("-?\\d+(\\.\\d+)?") ? new String[]{s2, s1} : null) …
Michael
  • 393
  • 2
  • 4
  • 20