OOP -> FP mindshift

Grasp the basic in less than

10 minutes

The Anonymous function powered by

λ

The λ expression allows us dynamically create:
functions and lexical scope

Functions as a first-class citizen


First-class function is a function that can be:
passed | returned | stored
as ANY other data without
ANY syntactic restrictions

Higher order functions

Technically is a function that takes as a argument other function/s

We gain: Computation extracting (Divide & Conquer) and
Function composition availability (DRY)

Closures and Partial Application together

Enclosing ANY data inside the lambda function.

Partial Application - give a second thought


result = f(x)(y)(z)
<=>
f1 = f(x) =>
f2 = f1(y) =>
f2(z) = result

Before immutablity...


CorrectState ∈ { (x , y), (x’, y’) } ErrorsState ∉ { (x’, y), (x , y’) }

(Pure , Total , Deterministic)
=>

Referencial transparency

Data modeling FP approach

ADT - Algebraic Data Types

					
						// ADT :: Product Type
						case class Status(code: Int, statusMessage: String) 
						// ADT :: Sum Type
						sealed trait Result
						object Success extends Result
						object Failed extends Result 
						// ADT :: Exponential Type
						type aFunctionalType = Status => Result
					
				

"Good OOP is nothing more then FP in disguise."

"Design patterns are for fill the gap of the OOP abstractions lack."

"With the power paradigm you don`t need any framework for DI."

"In FP it is a common practice to compose and build computation pipelines and defer evaluation until the end."

"In FP it is easy, and expected, to factor out common functionality into generic, reusable components that can be composed each other."

"Data structures just are. They don`t do anything."


But... Where IS the power of FP that we talk about?!

Takeaways

=> lambda and lexical scope

=> first class functions

=> higher order functions

=> partial application, currying, closures

=> function composition/chain

=> referencial transparency

=> ADT are power for domain/dsl modeling

Finish...

=> OOP Application is a squence of statmens written in imperative way where each statments is changing the program state.

=> FP is a sequence of exrepssion written in declarative way where each expressions represent a chain of transfromation without any chunks of mutability that could provoke hidden state change.

¡Muchas Gracias!

Thanks!