Functional Programming jargons

Page content

Side effects

Simply put side effects is when you update a value of a variable/global variable after its been set.

var result = 0
def add(a:Int, b:Int) {
    result = a+b //side effect
}
def add(a:Int, b:Int) = {
    return a+b //no side effect. no mutation happens here
}

Referentially Transparent

This is an awesome thing!. Its more or less like Idempotency. Anytime you call a function with same params it should always return the same output. Like multiplication table.

Partially Applied Functions

Partial Functions

It is not defined for some inputs. A function is called a partial function if it makes some assumptions about its inputs that are not implied by the input types.

Downcasting and UpCasting

Though down/up casting is not specific to FP, you would come across this at some point in your FP world. eg:

object Car {}
class Sedan extends Car {}
class Suv extends Car {}
class Camry extends Sedan {}
clas Rav4 extends Suv {}

Downcasting is say where a class/object is casted to its subtype. eg:

val someCar = new Sedan().asInstanceOf[Car]

Upcasting is when a class/object is casted to its parent type

val someSedan = new Sedan().asInstanceOf[Camry]