This document discusses Kotlin and the Arrow library. It provides an overview of Kotlin, describing it as an object-oriented, functional programming language that runs on the JVM and can be used for mobile, backend, and frontend development. It then covers functional programming concepts in Kotlin like higher-order functions, purity, immutability, and pattern matching. Finally, it introduces Arrow, an open source library that brings functional programming abstractions to Kotlin like data types for modeling absence, errors, and parallel errors to avoid nulls and exceptions.
Introduction to Kotlin and the speaker, Noe Luaces, sharing personal background.
Kotlin is a versatile language that supports object-oriented, functional programming, and is suitable for various applications, including mobile development.
Kotlin was developed by JetBrains in 2011, inspired to combine Scala’s features with Java's compiling speed.
Function types enable first-class functions in Kotlin, making them versatile and parametric.
Higher order functions accept other functions or lambda expressions as parameters, enhancing flexibility.
Pure functions are deterministic and side-effect-free, making them easier to test and predict.
Immutable objects improve thread safety, code cleanliness, and are preferred in Kotlin with 'val' keyword.
The 'when' construct allows advanced pattern matching in Kotlin, enhancing control flow without boilerplate.
Currying is breaking down functions into a series of single argument functions, streamlining function handling.
Kotlin features extensive null safety mechanisms to prevent null pointer exceptions and enhance stability.
Challenges involve avoiding exceptions for predictable failures, aiming for cleaner error handling.
Arrow is an open source library that enhances functional programming in Kotlin, akin to tools for Scala and Java.
The Option type in Arrow helps avoid null pointer exceptions by encapsulating possible values.
The Fold method is used to deal with Option values, handling cases for both presence and absence.
The Try type captures exceptions, allowing structured error handling and combining with other constructs.
Either represents a value that can either be an error or a successful outcome, facilitating error handling.
Example implementations demonstrating how to work with Either data structure and managing success or failure.
Validated collects multiple errors, providing a comprehensive error management strategy.
Summarizes key concepts of Kotlin and Arrow including functional programming principles and data types.
Highlights benefits of using Kotlin and Arrow in development such as syntax conciseness and functional patterns.
● Galician sinceI have memory (now living
in Barcelona)
● Avid comic book reader since I was a
teenager
● Software Engineer since October 2007
● Kotlin Developer since October 2018
> whoami
Designed to
interoperate fullywith
other JVM-based
languages
Object
Oriented
Great introductory
language to
functional
programming
Functional
Kotlin is...
6.
Designed to
interoperate fullywith
other JVM-based
languages
Object
Oriented
Great introductory
language to
functional
programming
Can be used in
backend, frontend or
as a script language
Functional
General
Purpose
Kotlin is...
7.
Designed to
interoperate fullywith
other JVM-based
languages
Object
Oriented
Great introductory
language to
functional
programming
Can be used in
backend, frontend or
as a script language
Functional
General
Purpose
Kotlin is...
Android has officially
adopted Kotlin as the
supported language
for mobile
development services
Mobile
Standard
8.
● Developed byJetBrains in 2011
● Its name comes from Kotlin island,
Russia
Kotlin background
9.
● JetBrains leadDmitry Jemerov said
that they were looking for a language
with the same features as Scala but
with a compilation velocity similar to
Java
Kotlin background
Higher Order Functions
●Functions that accept parameters typed as a function
● Functions that accept lambda expressions as parameters
18.
Higher Order Functions
●Scope functions like run, apply, let, with, also accept a lambda expression
● Other functions such as map, flatMap, filter, fold
Pure Functions
● Dependonly on the input to produce the result, not on any hidden
information or external state
● Have no observable side effects, like modifying a variable passed by
reference.
● Hence, they are easy to test
Immutable objects
● Remainin exactly the state in which they were created. Therefore, they are
thread-safe
● Are easier to write, use and they make cleaner code
● Make easier to parallelize the program as there are no conflicts among
objects
26.
Immutable objects
● Arepreferred whenever possible in Kotlin
● Are defined with the keyword val and can be initialized only single time
● Data classes, that hold the state which they were created with
The "when {}"block
● Advanced form of the switch-case statement known from Java
● No break statements are needed at the end of each case
30.
The "when {}"block
● Due smartcast, we can access methods or properties of the type without
extra checks
● Smartcast also works with subclasses providing a full pattern matching
● Could be used as an expression or a statement
Currying
● Is amathematical technique
● Consists on breaking down a function that takes multiple arguments into a
series of functions that each take only one argument
What is missing?
InFunctional Programming, we try to avoid throwing exceptions:
● For methods which fail often and predictably, like parsing user input as a
number, it’s costly and unnecessary to throw exceptions
● Handling checked exceptions can easily make the client’s code needlessly
complicated
Arrow background
● Opensource library sponsored by 47 Degrees
● Fusion between KATEGORY and funKTionale, the most
relevant FP libraries for Kotling in 2017
● First release was available in 2018
● Equivalent to Cats for Scala and Vavr for Java
Data type: Validated
●Collect all errors at once
● Possible values: Valid or Invalid
● Often used the typealias ValidatedNel ( instead of Validated<Nel>)
To sum up...
KOTLINARROW
HIGHER ORDER FUNCTIONS
IMMUTABILITY
PATTERN MATCHING
CURRYING
EITHER
OPTION
TRY
VALIDATIONS
66.
Why Kotlin?
● Concisesyntax
● Null safety
● Ease of transition from Java
● Interoperability with other JVM-based
languages
● Introductory language to functional
programming
● Android's adoption as the supported
language
67.
Why Arrow?
● Datatypes
● Type classes
● Effects
● Optics
● Other functional programming
patterns as higher- level abstractions
ready to use