When Life Gives You Java
26 points by petar
26 points by petar
With sufficient effort it’s possible to use almost any language like it’s Haskell!
This post scratches the surface. I can’t say I really disagree with much. I have written a fair amount of Java code in a pretty straightforward functional (wishy washy ish) style. If you can use the latest versions (bonus points for preview features), you will have a much better time at it: @FunctionalInterface(s), higher order functions (Producer, Callable, Supplier, Function, etc…), small compact types, sealed classes, records, switch statements, etc… These all play a part. The key is that you have to enforce a style across your codebase. Of course mixing in libraries like Vavr helps a lot as well.
How to bend a horse into a balloon.
This misses my favorite tool when writing Java: anonymous implementation of interfaces. On one side you write API’s that accept interfaces, on the other you conjure up the exact behavior you need right where you’re calling the API.