From the course: Functional Programming with Java
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Functional purity - Java Tutorial
From the course: Functional Programming with Java
Functional purity
- [Narrator] The second main concept of functional programming is something called functional purity. In functional programming, we aim to make all of our functions into pure functions. And what this means is that the functions we write should always return the same output, given the same arguments. And if this doesn't quite make sense to you yet, let's take a look at what functions that are not pure look like. Basically functions are not pure whenever they refer to some sort of internal or external state that changes. Now probably the most common example of this in Java is when you have methods in a class they're referred to a mutable member variable, let's say that we have a person class with a private age member variable, and then we have a method called get age, which simply returns the value of this age variable. This get age function is probably not pure and here's why. We can call it once and it might return some number like 34, basically whatever the person's age is at that…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.