Skip to Content
Scala Reactive Programming
book

Scala Reactive Programming

by Rambabu Posa
February 2018
Intermediate to advanced
552 pages
13h 46m
English
Packt Publishing
Content preview from Scala Reactive Programming

Referential transparency

In Scala, referential transparency (RT) means that an expression or a function call may be replaced by its value, without changing the behavior of the application.

A value may be replaced by an expression or a function call without changing the behavior of the application.

We will explore these two points with some simple examples now.

Let's assume that we are using the y = x + 1 expression in our application:

scala> val x = 10 
x: Int = 10 
 
scala> val y = x + 1 
y: Int = 11 
 
scala> val y = 11 
y: Int = 11 

Here, when we replace an expression x+1 with its value 11, it does not change any behavior of the y in our application:

scala> val y = 11 y: Int = 11 scala> def addOne(a: Int) = a + 1 addOne: (a: Int)Int scala> val ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Scala Programming Projects

Scala Programming Projects

Mikael Valot, Nicolas Jorand
Learning Scala

Learning Scala

Jason Swartz
Functional Programming in Scala

Functional Programming in Scala

Runar Bjarnason, Paul Chiusano

Publisher Resources

ISBN: 9781787288645Supplemental Content