SlideShare a Scribd company logo
Presented By: Deepak Mehra(Sr.Software Consultant)
Introduction to Vavr : A functional
Java library
Agenda
01
● What is Vavr?
● Prerequisite for Vavr
● Tuples
● Functions
● Values
● Collections
● Pattern Matching
● Demo
What is Vavr?
01
● Vavr is essentially a functional Java library which aims to extend the features of Java8 and helps to
reduce the amount of code and increase code quality.
● It provides collections, functional interfaces for error handling, concurrent programming, and
pattern matching. There are many other modules which revolves around vavr core.
● Also, It provides immutable data structures(cannot be modified once created), persistent data
structures(does preserve the previous version of itself when being modified), functional data
structures(also known as purely functional data structures), they are immutable and persistent.
Prerequisite for Vavr
01
● Java8
● Maven/Gradle
Tuples
01
You must have seen Tuples in Scala if you have ever worked on Scala. Tuple is nothing but a data
structure which will have fixed number of elements and can hold objects of heterogeneous
types(different types).
Functions
01
In Java8 we have Function which accepts one parameter and BiFunction which accepts two
parameters and gives output whereas vavr provides functions with upto a limit of 8 parameters.
The functional interfaces are like this Function0, Function1, Function2 and so on.
Values
01
● Option
● Try
● Lazy
● Either
● Future
● Collections
● Pattern Matching
Values
01
An expression which can be further evaluated for calculations or other. In Java, this can be
expressed by making the state of an object final and call it immutable. Vavr’s functional value
abstracts over immutable objects. If variable and objects are immutable their state is unmodifiable
and unchangeable which provides thread safety. So, we can share the variable without any fear in
a multi threaded environment.
Option
01
Option – We saw Option in Scala language. However, in Java something similar was introduced
with the help Optional class which behaves pretty much similar to Scala’s Option. Instances of
Option are either an instance of Some or None. Honestly speaking I don’t see much difference in
Scala’s Option and Java’s Optional.
Try
01
Try – Try is nothing but a container that represents a computation that may either result in an
exception or return a value. This looks similar to Either but it is different than that. Instances of Try,
are either Success or Failure
Lazy
01
Lazy – Lazy is a container which will represent a lazy evaluated value. Lazy is memoized already, it
evaluates only once and next time onwards returns from a cache.
Either
01
Either – An instance of Either is either an instance of Left or Right. A common use of Either is as an
alternative to Option for dealing with possible missing values. You can relate it Option as well, so
Left is considered to be None type and Right is considered to be Some type. Instance Right will
hold success and Left will hold failure.
Future
01
Future – A Future represents the result of an asynchronous computation. When the asynchronous
task is created, a future object is returned
There is a get() with Futures which will compute the result from Future but it is blocking in nature. It
also has isComplete() which returns a boolean value to mention if a future has been completed.
A future has two states: pending and completed
Future
01
Pending – The computation is on going. A pending future may be completed or cancelled.
Completed – The computation finished successfully with a result, failed with an exception or
cancelled.
Java8 already has a rich set of APIs for future. Future has been there since Java5 and it has
improved with time. Java8 has provided improvements to it. Now, we have
CompletableFuture(class) and CompletionStage(interface) with several callback methods.
I personally love Java8’s future API. Vavr has also introduced future class in the library with some
additional feature which we can play around with.
Collections
01
Collections – In vavr library a new collection library has been introduced to meet the functional
requirements, which is immutable in nature. Vavr library will essentially reduce the boilerplate code
which we will see going forward. This new collection is essentially based on java.lang.Iterable.
List in Vavr – Vavr list is essentially an immutable linked list. Mutations will result in new instances.
Pattern Matching
01
Pattern matching was not introduced as part of Java8, although we have worked with pattern
matching in Scala but Java never had it. Vavr library has support for pattern matching, now you can
also use pattern matching in Java8.
In pattern matching match is essentially an expression which yields some result. Also, pattern
matching is really a great feature to save a lot of time as it avoids to write if else branches and the
code looks more clean and readable.
Vavr library provides a match API which is pretty much similar to Scala’s pattern matching.
Pattern Matching
01
Pattern matching was not introduced as part of Java8, although we have worked with pattern
matching in Scala but Java never had it. Vavr library has support for pattern matching, now you can
also use pattern matching in Java8.
In pattern matching match is essentially an expression which yields some result. Also, pattern
matching is really a great feature to save a lot of time as it avoids to write if else branches and the
code looks more clean and readable.
Vavr library provides a match API which is pretty much similar to Scala’s pattern matching.
References
01
● https://www.vavr.io/vavr-docs/
● https://github.com/vavr-io/vavr
● https://blog.knoldus.com/introduction-to-vavr-a-functional-library-for-java/
● https://blog.knoldus.com/functional-java-how-to-do-pattern-matching-in-java/
Thank You !

More Related Content

PPTX
Introduction to Scala
PPTX
Java 101 intro to programming with java
ODP
String interpolation
PPTX
Java basic
PDF
Functional Programming in Java
PPTX
OCA Java SE 8 Exam Chapter 1 Java Building Blocks
PPTX
OCA Java SE 8 Exam Chapter 2 Operators & Statements
PPTX
OCP Java (OCPJP) 8 Exam Quick Reference Card
Introduction to Scala
Java 101 intro to programming with java
String interpolation
Java basic
Functional Programming in Java
OCA Java SE 8 Exam Chapter 1 Java Building Blocks
OCA Java SE 8 Exam Chapter 2 Operators & Statements
OCP Java (OCPJP) 8 Exam Quick Reference Card

What's hot (20)

PPTX
java 8 new features
PDF
Xtend - better java with -less- noise
PPTX
Java 102 intro to object-oriented programming in java
PPTX
Intro to Scala
PDF
Functional programming with Java 8
PPTX
Functional programming principles and Java 8
PPTX
Java 8 Features
DOCX
Java interview questions and answers for cognizant By Data Council Pune
PDF
Functional programming in scala
PPTX
JavaScripts internals #1
PPT
Java findamentals1
PPT
Java findamentals1
PPT
Java findamentals1
PPTX
Core java
PDF
Bt0074 oops with java
PPTX
Functional Programming In Jdk8
PDF
Java Review
PDF
Functional programming with Xtend
PDF
From Java to Kotlin
PPTX
Virtual function and abstract class
java 8 new features
Xtend - better java with -less- noise
Java 102 intro to object-oriented programming in java
Intro to Scala
Functional programming with Java 8
Functional programming principles and Java 8
Java 8 Features
Java interview questions and answers for cognizant By Data Council Pune
Functional programming in scala
JavaScripts internals #1
Java findamentals1
Java findamentals1
Java findamentals1
Core java
Bt0074 oops with java
Functional Programming In Jdk8
Java Review
Functional programming with Xtend
From Java to Kotlin
Virtual function and abstract class
Ad

Similar to Introduction To Vavr: A Functional Java Library (20)

PPTX
Learn scala and it's componenents learn it
PPT
scala-intro
PPTX
JAVA AND OOPS CONCEPTS.pptx helpful for engineering
PPTX
Java interview questions 2
PDF
Volatile keyword
DOCX
100 Java questions FOR LOGIC BUILDING SOFTWARE.docx
PPTX
Java_Interview Qns
PDF
Java Basics Presentation
KEY
Java Closures
PDF
Java Faqs useful for freshers and experienced
PDF
Top 371 java fa qs useful for freshers and experienced
KEY
LSUG: How we (mostly) moved from Java to Scala
DOCX
Java Interview Questions For Freshers
PDF
Java Bytecode Verification for NonNull Types 1st Edition by Chris Male, David...
PDF
Top 30 Java Phone Interview Questions Answers for Freshers, 1 to 2 Years Expe...
PPT
Chapter1pp
 
PDF
20 most important java programming interview questions
PDF
Core Java Interview Questions PDF By ScholarHat
PDF
50+ java interview questions
PPTX
Object-Oriented Programming with Java UNIT 1
Learn scala and it's componenents learn it
scala-intro
JAVA AND OOPS CONCEPTS.pptx helpful for engineering
Java interview questions 2
Volatile keyword
100 Java questions FOR LOGIC BUILDING SOFTWARE.docx
Java_Interview Qns
Java Basics Presentation
Java Closures
Java Faqs useful for freshers and experienced
Top 371 java fa qs useful for freshers and experienced
LSUG: How we (mostly) moved from Java to Scala
Java Interview Questions For Freshers
Java Bytecode Verification for NonNull Types 1st Edition by Chris Male, David...
Top 30 Java Phone Interview Questions Answers for Freshers, 1 to 2 Years Expe...
Chapter1pp
 
20 most important java programming interview questions
Core Java Interview Questions PDF By ScholarHat
50+ java interview questions
Object-Oriented Programming with Java UNIT 1
Ad

More from Knoldus Inc. (20)

PPTX
Angular Hydration Presentation (FrontEnd)
PPTX
Optimizing Test Execution: Heuristic Algorithm for Self-Healing
PPTX
Self-Healing Test Automation Framework - Healenium
PPTX
Kanban Metrics Presentation (Project Management)
PPTX
Java 17 features and implementation.pptx
PPTX
Chaos Mesh Introducing Chaos in Kubernetes
PPTX
GraalVM - A Step Ahead of JVM Presentation
PPTX
Nomad by HashiCorp Presentation (DevOps)
PPTX
Nomad by HashiCorp Presentation (DevOps)
PPTX
DAPR - Distributed Application Runtime Presentation
PPTX
Introduction to Azure Virtual WAN Presentation
PPTX
Introduction to Argo Rollouts Presentation
PPTX
Intro to Azure Container App Presentation
PPTX
Insights Unveiled Test Reporting and Observability Excellence
PPTX
Introduction to Splunk Presentation (DevOps)
PPTX
Code Camp - Data Profiling and Quality Analysis Framework
PPTX
AWS: Messaging Services in AWS Presentation
PPTX
Amazon Cognito: A Primer on Authentication and Authorization
PPTX
ZIO Http A Functional Approach to Scalable and Type-Safe Web Development
PPTX
Managing State & HTTP Requests In Ionic.
Angular Hydration Presentation (FrontEnd)
Optimizing Test Execution: Heuristic Algorithm for Self-Healing
Self-Healing Test Automation Framework - Healenium
Kanban Metrics Presentation (Project Management)
Java 17 features and implementation.pptx
Chaos Mesh Introducing Chaos in Kubernetes
GraalVM - A Step Ahead of JVM Presentation
Nomad by HashiCorp Presentation (DevOps)
Nomad by HashiCorp Presentation (DevOps)
DAPR - Distributed Application Runtime Presentation
Introduction to Azure Virtual WAN Presentation
Introduction to Argo Rollouts Presentation
Intro to Azure Container App Presentation
Insights Unveiled Test Reporting and Observability Excellence
Introduction to Splunk Presentation (DevOps)
Code Camp - Data Profiling and Quality Analysis Framework
AWS: Messaging Services in AWS Presentation
Amazon Cognito: A Primer on Authentication and Authorization
ZIO Http A Functional Approach to Scalable and Type-Safe Web Development
Managing State & HTTP Requests In Ionic.

Recently uploaded (20)

PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
System and Network Administration Chapter 2
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
medical staffing services at VALiNTRY
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PPTX
ai tools demonstartion for schools and inter college
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PPTX
Reimagine Home Health with the Power of Agentic AI​
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
System and Network Administraation Chapter 3
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PPTX
history of c programming in notes for students .pptx
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
 
PPTX
L1 - Introduction to python Backend.pptx
PPTX
Introduction to Artificial Intelligence
PDF
AI in Product Development-omnex systems
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
2025 Textile ERP Trends: SAP, Odoo & Oracle
Internet Downloader Manager (IDM) Crack 6.42 Build 41
System and Network Administration Chapter 2
Odoo Companies in India – Driving Business Transformation.pdf
medical staffing services at VALiNTRY
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
ai tools demonstartion for schools and inter college
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Reimagine Home Health with the Power of Agentic AI​
Odoo POS Development Services by CandidRoot Solutions
System and Network Administraation Chapter 3
How to Choose the Right IT Partner for Your Business in Malaysia
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
history of c programming in notes for students .pptx
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
 
L1 - Introduction to python Backend.pptx
Introduction to Artificial Intelligence
AI in Product Development-omnex systems

Introduction To Vavr: A Functional Java Library

  • 1. Presented By: Deepak Mehra(Sr.Software Consultant) Introduction to Vavr : A functional Java library
  • 2. Agenda 01 ● What is Vavr? ● Prerequisite for Vavr ● Tuples ● Functions ● Values ● Collections ● Pattern Matching ● Demo
  • 3. What is Vavr? 01 ● Vavr is essentially a functional Java library which aims to extend the features of Java8 and helps to reduce the amount of code and increase code quality. ● It provides collections, functional interfaces for error handling, concurrent programming, and pattern matching. There are many other modules which revolves around vavr core. ● Also, It provides immutable data structures(cannot be modified once created), persistent data structures(does preserve the previous version of itself when being modified), functional data structures(also known as purely functional data structures), they are immutable and persistent.
  • 4. Prerequisite for Vavr 01 ● Java8 ● Maven/Gradle
  • 5. Tuples 01 You must have seen Tuples in Scala if you have ever worked on Scala. Tuple is nothing but a data structure which will have fixed number of elements and can hold objects of heterogeneous types(different types).
  • 6. Functions 01 In Java8 we have Function which accepts one parameter and BiFunction which accepts two parameters and gives output whereas vavr provides functions with upto a limit of 8 parameters. The functional interfaces are like this Function0, Function1, Function2 and so on.
  • 7. Values 01 ● Option ● Try ● Lazy ● Either ● Future ● Collections ● Pattern Matching
  • 8. Values 01 An expression which can be further evaluated for calculations or other. In Java, this can be expressed by making the state of an object final and call it immutable. Vavr’s functional value abstracts over immutable objects. If variable and objects are immutable their state is unmodifiable and unchangeable which provides thread safety. So, we can share the variable without any fear in a multi threaded environment.
  • 9. Option 01 Option – We saw Option in Scala language. However, in Java something similar was introduced with the help Optional class which behaves pretty much similar to Scala’s Option. Instances of Option are either an instance of Some or None. Honestly speaking I don’t see much difference in Scala’s Option and Java’s Optional.
  • 10. Try 01 Try – Try is nothing but a container that represents a computation that may either result in an exception or return a value. This looks similar to Either but it is different than that. Instances of Try, are either Success or Failure
  • 11. Lazy 01 Lazy – Lazy is a container which will represent a lazy evaluated value. Lazy is memoized already, it evaluates only once and next time onwards returns from a cache.
  • 12. Either 01 Either – An instance of Either is either an instance of Left or Right. A common use of Either is as an alternative to Option for dealing with possible missing values. You can relate it Option as well, so Left is considered to be None type and Right is considered to be Some type. Instance Right will hold success and Left will hold failure.
  • 13. Future 01 Future – A Future represents the result of an asynchronous computation. When the asynchronous task is created, a future object is returned There is a get() with Futures which will compute the result from Future but it is blocking in nature. It also has isComplete() which returns a boolean value to mention if a future has been completed. A future has two states: pending and completed
  • 14. Future 01 Pending – The computation is on going. A pending future may be completed or cancelled. Completed – The computation finished successfully with a result, failed with an exception or cancelled. Java8 already has a rich set of APIs for future. Future has been there since Java5 and it has improved with time. Java8 has provided improvements to it. Now, we have CompletableFuture(class) and CompletionStage(interface) with several callback methods. I personally love Java8’s future API. Vavr has also introduced future class in the library with some additional feature which we can play around with.
  • 15. Collections 01 Collections – In vavr library a new collection library has been introduced to meet the functional requirements, which is immutable in nature. Vavr library will essentially reduce the boilerplate code which we will see going forward. This new collection is essentially based on java.lang.Iterable. List in Vavr – Vavr list is essentially an immutable linked list. Mutations will result in new instances.
  • 16. Pattern Matching 01 Pattern matching was not introduced as part of Java8, although we have worked with pattern matching in Scala but Java never had it. Vavr library has support for pattern matching, now you can also use pattern matching in Java8. In pattern matching match is essentially an expression which yields some result. Also, pattern matching is really a great feature to save a lot of time as it avoids to write if else branches and the code looks more clean and readable. Vavr library provides a match API which is pretty much similar to Scala’s pattern matching.
  • 17. Pattern Matching 01 Pattern matching was not introduced as part of Java8, although we have worked with pattern matching in Scala but Java never had it. Vavr library has support for pattern matching, now you can also use pattern matching in Java8. In pattern matching match is essentially an expression which yields some result. Also, pattern matching is really a great feature to save a lot of time as it avoids to write if else branches and the code looks more clean and readable. Vavr library provides a match API which is pretty much similar to Scala’s pattern matching.
  • 18. References 01 ● https://www.vavr.io/vavr-docs/ ● https://github.com/vavr-io/vavr ● https://blog.knoldus.com/introduction-to-vavr-a-functional-library-for-java/ ● https://blog.knoldus.com/functional-java-how-to-do-pattern-matching-in-java/