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.
2. ● Galician since I 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
5. Designed to
interoperate fully with
other JVM-based
languages
Object
Oriented
Great introductory
language to
functional
programming
Functional
Kotlin is...
6. Designed to
interoperate fully with
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 fully with
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 by JetBrains in 2011
● Its name comes from Kotlin island,
Russia
Kotlin background
9. ● JetBrains lead Dmitry 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
17. 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
21. Pure Functions
● Depend only 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
25. Immutable objects
● Remain in 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
● Are preferred 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
29. 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
34. Currying
● Is a mathematical technique
● Consists on breaking down a function that takes multiple arguments into a
series of functions that each take only one argument
39. What is missing?
In Functional 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
41. Arrow background
● Open source 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
52. Data type: Either
● Represents a value with two possibilities
● Left (error case) or Right (happy case)
● Allows to fail fast providing all the context
61. Data type: Validated
● Collect all errors at once
● Possible values: Valid or Invalid
● Often used the typealias ValidatedNel ( instead of Validated<Nel>)
65. To sum up...
KOTLIN ARROW
HIGHER ORDER FUNCTIONS
IMMUTABILITY
PATTERN MATCHING
CURRYING
EITHER
OPTION
TRY
VALIDATIONS
66. Why Kotlin?
● Concise syntax
● 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?
● Data types
● Type classes
● Effects
● Optics
● Other functional programming
patterns as higher- level abstractions
ready to use