// 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
// Partial Type Application via alias
type T[A] = Option[Map[Int, A]]
val t: T[String] = Some(Map(1 -> "abc", 2 -> "xyz"))
OOP <=> encapsulate/couples state and behaviour.
FP <=> decouple them.
"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?!
Everything is around Context!
The comprehension of for-comprehension expression
For-comprehension - a syntactic sugar for combination flatMap(s)/map together in a readable form
=> 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 expression represent a chain of transfromation without any chunks of mutability
that could provoke hidden state change.
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.
More and more about FP
=> Pattern Matching - power of the types
=> Type classes vs. Interfaces
=> Kinds - as a labels for the types
=> GADTs - Generalized ADT
=> Partial Type Application/Type Level Programming