What is monad emulation in Java?
I know that in scala and many other functional languages, monad is mainly an interface implementation (for example, using flatmap [t] and unit [t] methods in scala). Is there any Java style interface that can be monad?
Solution
There are two problems with representing monad in Java:
Flatmap needs to operate on a function that returns (the same) a specific monad, which the Java type system cannot express
Unit is a static method in Java terminology because it creates monad instances from common values Java 8 has static methods on the interface, but the abstract monad interface cannot know the implementation, so you must use factory methods elsewhere (or only constructors)
As @ Alexey Romanov suggested, you can implement a specific monad (for example, create an option interface), but it is impossible to use the abstract concept of monad in Java This of course means that you cannot create all the useful functions for any monad