Hi Deepak!
Deepak Lal wrote:
1. how is your functional programming book different from other books like Java 8 in action
In another post, I compared it to Pierre-Ives Saumont's "Functional Programming with Java". In essence, it approaches its topic more from the Java side of view and how a "typical OO/imperative-focused " Java dev can utilize the new tools since Java 8+ to incorporate FP(-akin) techniques.
Compared to "Java 8 in Action", my book doesn't use an exercise/answer or recipe-like style, as I don't like that very much in books I read myself.
I like to discuss features under the focus of the benefits of functional principles, and present the pros and cons, and if available, what's on the horizon in upcoming JDKs.
2.what are the positive takeaways from the book
Hopefully, the readers will see the benefits of a more functional approach, even in a language like Java that's, let's be honest, not the best choice for functional programming if you can choose any language you want.
But a functional mindset is the first step to benefiting from functional concepts and principles even without needing to go fully functional.
Things like immutability with Records, declarative data processing with Streams, or improved null-handling with Optionals are great features, even in non-functional code.
3.Could you give me some insights about the book -> A Functional approach to Java
I'm not sure I understand the question or how to answer it...
The page in my signature has the table of contents and what you'll learn.
The
book's repository is split into the same parts/chapters as the book and shows how I approach the topics.
4.can you explain any concept from your book with a java 8 example
I think a full-blown example might be too big for a post, but I try to explain how to improve null-handling with Optionals
Think of this code for loading content from a database:
It's a lot of lines for a mix of null- and data-checks, and you still have to check the returned content.
With Optionals, on the other hand, you have a scaffold a value can traverse and be transformed in a fluent code.
This leads to less code that's even more straightforward and easier to reason with:
The code does the same as before, but uses an Optional to wrap up the content.
The JDK now does all the check in the different operations of the Optional pipeline, with little noise thanks to method references.
You still have to check for the existence of the content, but now you have a declarative jump-off point instead of a "dead end" if-null-check.
This is a way how approached many topics.
First, discuss a problem and how it's done without any of the Java 8+ features or functional principles in mind.
Next, how can we improve it.
And last, what new problems might arise, or what you have to look out for.