Skip to content

Instantly share code, notes, and snippets.

Created Nov 18, 2015
What would you like to do?
How a Java 8 Stream acts as a Functor
import java.util.function.Function;
public class Example {
static class A {}
static class B {}
static class C {}
static B aToB(A a) { return new B(); }
static C bToC(B b) { return new C(); }
static Function<Stream<A>, Stream<B>> streamAToStreamB
= streamA ->;
static Function<Stream<B>, Stream<C>> streamBToStreamC
= streamA ->;
static Function<Stream<A>, Stream<C>> streamAtoStreamC
= streamA -> streamBToStreamC.apply(streamAToStreamB.apply(streamA));
static Function<Stream<A>, Stream<C>> streamAtoStreamC2
= streamA -> -> bToC(aToB(a)));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment