5
votes
1answer
265 views

Are the Streams in Java 8 monads?

It seems like the Optional in Java 8 is a monad. Are the Streams also monads? Can anyone identify the endofunctor and the two natural transformations in the optional monad?
4
votes
1answer
60 views

Java 8 functional: How to compute a list of dependent evolutions of an object?

I want to write the following code in a functional way with streams and lambdas: Thing thing = new Thing(); List<Thing> things = new ArrayList<>(); things.add(thing); for (int i = 0; i ...
3
votes
4answers
252 views

Does Java SE 8 have Pairs or Tuples?

I am playing around with lazy functional operations in Java SE 8, and I want to map an index i to a pair / tuple (i, value[i]), then filter based on the second value[i] element, and finally output ...
9
votes
1answer
201 views

A java List that implements the new Stream interface?

I just took some time to start looking into the java-8 buzz about streams and lambdas. And have a couple of questions... The first thing that surprised me is that you cannot apply the Stream ...
2
votes
1answer
75 views

Java 8 Stream API to denormalize Map<A, Set<B>> to Map<B, A> without a Pair

I want to do something like the following, but I want to know if there is a more elegant way to do it without the Pair class. The Pair class no longer exists so I would have to create my own class, ...
1
vote
1answer
34 views

Check order of two elements in Java-8-Stream

I want to check the order of two elements in a Java-8-Stream. I have this Iterator-Solution: public static boolean isBefore (A a1, A a2, ...
2
votes
2answers
98 views

How to shuffle a stream using the Stream API?

I decided to take the functional approach in generating a string or random characters, so far I came up with this, it should perform better than boxing and then using a StringJoiner as collector: ...
3
votes
1answer
104 views

Finding average using reduce and collect

I am trying to understand the new Java 8 Stream APIs. http://docs.oracle.com/javase/tutorial/collections/streams/reduction.html I found the example of finding average of numbers using collect API. ...
0
votes
2answers
65 views

How to use an infinite java.util.stream.Stream?

Say I have an infinite Stream: Stream<Socket> stream = Stream.generate(() -> { try { return serverSocket.accept(); } catch (IOException e) { throw new ...