Skip to main content

Posts

Showing posts with the label referential transparency

Functional programming in Java 8

In my previous post, we discussed about why we should consider to use functional programming. Now, let's delve into what functional programming in Java is.
What is pure functional programming?Shortly, functional programming is programming using functions. A function corresponds to a mathematical function such as log, sin. Basically, it takes zero or more arguments, give one or more result, and has no side effects.
We can't completely program in pure functional style in Java Why?  For example, calling Scanner.nextLine twice typically gives different result.

So, it's just called "functional-style programming". How is that?
- There is no mutating structures visible to callers. That means your side effect may not be visible to a program, but it's visible to the programmer in terms of slower execution.
- A function or method shouldn't throw any exceptions (follows the concept "pass arguments, return result"). We can use types like Optional<T> i…