The standarized open ladder of Functional programming

with Java & VAVR (Level 1 2 3)

#EYD

Juan Antonio Breña Moral

v0.4.0-SNAPSHOT

Control version

  1. Functional concepts (Pune - October 2019)
  2. Functional patterns (Brussels & Madrid - November 2019)
  3. Standardized Open Ladder of functional programming, Level 1 on Java (December 2019)

Who I am

Juan Antonio Breña Moral (40)
Chapter Lead, Deejay & Mindstorms/STEAM teacher.
Twitter | Github | Linkedin
Purpose: "Riding dragons with innovation & fun"
Quote: "Pressure makes diamonds."
- George S. Patton Jr.

“Production is the best place on the Internet.”

- Josh Long

Agenda

  1. Goals
  2. Functional programming
  3. A Roadmap
  4. SOLFP Level 1
  5. SOLFP Level 2
  6. SOLFP Level 3
  7. Sharpening the axe
  8. Acknowledgements
  9. Future talks

Goals

I wish the audience could:

  1. Explain the Standardized open ladder of functional programming
  2. Use functional composition in the daily job
  3. Design with better Types

Functional programming

functional programming is a programming paradigm style of building the structure and elements of computer programs—that treats computation as the evaluation of mathematical functions and avoids changing-state and mutable data.

You can model solutions using this paradigm with Scala, Clojure, Kotlin & Java in the JVM.

Wikipedia

Functional programming

Functional programming

Java 8+

Functional programming

VAVR

A roadmap

Standardized open ladder of functional programming

Further information

SOLFP Level 1

Agenda:

  1. Immutable Data
  2. Second-Order Functions
  3. Constructoring & Destructuring
  4. Function Composition
  5. Lambdas

SOLFP Level 1

Skills:

  1. Use second-order functions (map, filter, fold) on immutable data structures
  2. Use data types to represent optionality
  3. Read basic type signatures
  4. Pass lambdas to second-order functions

Immutable Data

java.util.*

Immutable Data

io.vavr.collection.*

Immutable Data

Performance Characteristics of Vavr Collections

Immutable Data

Performance Characteristics of Vavr Collections

Constructoring & Destructuring

Destructuring is a special syntax that allows us to “unpack” arrays or objects into a bunch of variables.

Functional composition

Function composition is a mechanism to combine simple functions to build more complicated ones.

The ability to easily compose functions encourages factoring (breaking apart) functions for maintainability and code reuse.

Lambdas

Lambda expressions provide a clear and concise way to represent one method interface using an expression.

Lambdas

java.util.function.*

  • Predicate: A property of the object passed as argument
  • Consumer: An action to be performed with the object passed as argument
  • Function: Transform a T to a U
  • Supplier: Provide an instance of a T (such as a factory)
  • UnaryOperator: A unary operator from T -> T
  • BinaryOperator: A binary operator from (T, T) -> T

SOLFP Level 2

Agenda:

  1. Algebraic Data Types (Java 14*)
  2. Pattern Matching (Java 14*)
  3. General Recursion
  4. Type Classes, instances, & Laws
  5. Lower-Order Abstractions (Equal, Semigroup, Monoid, etc)
  6. Referential Transparency & Totality
  7. Higher-Order Functions
  8. Partial-Application, Currying, & Point-Free Style

SOLFP Level 2

Skills:

  1. Solve problems without nulls, exceptions, or type casts
  2. Process & transform recursive data structures using recursion
  3. Able to use functional programming “in the small”
  4. Write basic monadic code for a concrete monad
  5. Model a business domain with ADTs
  6. Write functions that take and return functions

SOLFP Level 3

Agenda:

  1. Generalized Algebraic Data Types
  2. Higher-Kinded Types
  3. Rank-N Types
  4. Folds & Unfolds
  5. Higher-Order abstractions (Category, Functor, Monad)
  6. Basic Optics
  7. Efficient Persistent Data Structures
  8. Embedded DSLs using Combinators

SOLFP Level 3

Skills:

  1. Test code using generators and properties
  2. Write imperative code in a purely functional way through monads
  3. Separate decision from effects
  4. Write a simple custom lawful monad
  5. Write production medium-sized projects
  6. Use lenses & prisms to manipulate data
  7. Simplify types by hiding irrelevant data with existentials

SOLFP Level 3

Sharpening the axe

  • Euler: Synchronous problems
  • Latency: Asynchronous problems

Acknowledgements

Future talks

@juanantoniobm

Thanks