SlideShare a Scribd company logo
Please open the following URLs:
This presentation: https://goo.gl/1teY4Q
Code repo: https://goo.gl/GY9Fgn
Kotlin’ize
your App
Hello!I am Renato Almeida
You can find me at @tallnato (on the places I fit)
Because I am big, like BIG
Hello!I am Pedro Vicente
You can find me at @neteinstein (all over the place)
… and I’m the beautiful one of this talk!
Yeah, that company from Oporto
that works in self-organization
Mindera
This is a tale of our
experience!
Our team moved 99% of our
codebase to kotlin
1.
Why kotlin
And not just stick with Java?
× Java’s null-unsafety !!!!!!!!!!!!!!!!!!!!!!!!!!!
× Android doesn’t have the new bells and whistles of
Java (8+)
× Java’s base is procedural, not functional
Why NOT JAVA
× Kotlin is 100% interoperable with Java
× Yes, really.
× Kotlin isn’t as verbose
× Everybody knows… the less code, the less bugs
× Kotlin is fun (pun intended)
× And we have var and val, let, apply….
Why kotlin
× Extensions!
× Very fast learning curve
× You can do magic with it, no, for real!
Why kotlin
× Kotlin Standard Library adds 800Kb to the .apk
× Kotlin is from Russia. You need Vodka.
× Ok... it’s just the first one.
Drawbacks
2.
COde
code, code, code
Kotlin types
CREDITS TO: https://github.com/JetBrains/kotlin-workshop
Hands on
Let’s rock and roll!
RememberYou can use automatic conversion… but if you
aren’t using the fun stuff on Kotlin…
what’s the .?
Let’s get the magic going
OPERATORS COLLECTIONS MAGIC
Kotlin operators
CREDITS TO: https://github.com/JetBrains/kotlin-workshop
Kotlin operators
CREDITS TO: https://github.com/JetBrains/kotlin-workshop
Kotlin operators
CREDITS TO: https://github.com/JetBrains/kotlin-workshop
Kotlin operators
CREDITS TO: https://github.com/JetBrains/kotlin-workshop
Kotlin operators
CREDITS TO: https://github.com/JetBrains/kotlin-workshop
Kotlin operators
CREDITS TO: https://github.com/JetBrains/kotlin-workshop
Let’s get the magic going
OPERATORS COLLECTIONS MAGIC
val list = listOf(1, 2, 3, 4, 5, 6)
//Returns true if at least one element matches the given predicate.
list.any { it % 2 == 0 } //TRUE
list.any { it > 10 } // FALSE
//Returns true if all match the given predicate
list.all { it < 10 } //TRUE
list.all { it % 2 == 0 } //FALSE
//Returns the number of elements matching the given predicate.
list.count { it % 2 == 0 } // 3
val list = listOf(1, 2, 3, 4, 5, 6)
//Accumulates the value: starts with initial value
//and applies an operation from the first to the last
element in a collection.
list.fold(4) { total, next -> total + next } //25
//Same as fold, but goes from the last element to first
list.foldRight(4) { total, next -> total + next } //25
//Same as fold without initial value
list.reduce { total, next -> total + next } //21
//Same as foldRight without initial value
list.reduceRight { total, next -> total + next } //21
val list = listOf(1, 2, 3, 4, 5, 6)
//No comments
list.forEach { println(it) }
//Also, no comments
list.forEachIndexed { index, value -> println("position $index contains a $value") }
//Returns Max, the dog
list.max() // 6
//Returns Minion
list.min() // 1
val list = listOf(1, 2, 3, 4, 5, 6)
//Returns the first element yielding the largest value of the given function or null if there are no elements.
list.maxBy { -it } //1
//Same logic for min
list.minBy { -it } //6
//If none of the elements matches condition
list.none { it % 7 == 0 } //TRUE
//Returns the sum of all values produced by the transform function from the elements in the collection
list.sumBy { it % 2 } //3
val list = listOf(1, 2, 3, 4, 5, 6)
//Returns a list containing all elements except first n elements.
list.drop(4) //5, 6
//Returns a list containing all elements except first elements that satisfy the given predicate.
list.dropWhile { it < 3 } //3, 4, 5, 6
//Returns a list containing all elements except last elements that satisfy the given predicate.
list.dropLastWhile { it > 4 } //1, 2, 3, 4
//Returns a list containing all elements matching the given predicate.
list.filter { it % 2 == 0 } //2, 4, 6
//Returns a list containing all elements not matching the given predicate.
list.filterNot { it % 2 == 0 } //1, 3, 5
val list = listOf(1, 2, 3, 4, 5, 6)
//Returns a list containing elements at specified indices.
list.slice(listOf(1, 3, 4)) //2, 4, 5
//Returns a list containing first n elements
list.take(2) //1, 2
//Returns a list containing last n elements.
list.takeLast(2) //5, 6
//Returns a list containing first elements satisfying the given predicate.
list.takeWhile { it < 3 } //1, 2
val list = listOf(1, 2, 3, 4, 5, 6)
//Returns a list containing the results of applying
//the given transform function to each element and
//its index of the original collection.
list.mapIndexed { index, it -> index * it }
//Returns true if the element is found in the collection.
list.contains(2) // TRUE
//Returns an element at the given index or throws an //IndexOutOfBoundsException if the index is out
//of bounds of this collection.
list.elementAt(1) //2
val list = listOf(1, 2, 3, 4, 5, 6)
//Iterates over the elements creating a new collection for each one,
//and finally flattens all the collections into a unique list containing all the elements.
list.flatMap { listOf(it, it + 1) } //1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7
//Returns a map of the elements in original collection grouped by the result of given function
list.groupBy { if (it % 2 == 0) "even" else "odd" }//mapOf("odd" to listOf(1, 3, 5), "even" to listOf(2, 4, 6)), 2
//Returns a list containing the results of applying the given transform function to each element of the original
collection.
list.map { it * 2 } //2, 4, 6, 8, 10, 12
val list = listOf(1, 2, 3, 4, 5, 6)
//Returns an element at the given index or the result of calling the default function if the index is out of bounds
of this collection.
list.elementAtOrElse(10, { 2 * it }) //20
//Returns an element at the given index or null if the index is out of bounds of this collection.
list.elementAtOrNull(10) // null
//Returns an element at the given index or throws an IndexOutOfBoundsException if the index is out of bounds
of this collection.
list.elementAt(1) //2
//Returns an element at the given index or the result of calling the default function if the index is out of bounds
of this collection.
list.elementAtOrElse(10, { 2 * it }) //20
val list = listOf(1, 2, 3, 4, 5, 6)
//Returns an element at the given index or null if
the index is out of bounds of this collection.
list.elementAtOrNull(10) // null
//Returns the first element matching the given predicate
, or null if no element was found.
list.firstOrNull { it % 7 == 0 } //null
//Returns the first index of element, or -1 if the collection does not contain element.
list.indexOf(4) //3
//Returns index of the first element matching the given predicate, or -1 if the collection does not contain such
element.
list.indexOfFirst { it % 2 == 0 } //1
val list = listOf(1, 2, 3, 4, 5, 6)//Returns index of the last element matching the given predicate, or -1 if the collection does not contain
such element.
list.indexOfLast { it % 2 == 0 } //5
//Returns the last element matching the given predicate.
list.last { it % 2 == 0 } // 6
//Returns the single element matching the given predicate, or throws exception if there is no or more
than one matching element.
list.single { it % 5 == 0 } // 5
//Returns the single element matching the given predicate, or null if element was not found or more than
one element was found.
list.singleOrNull { it % 7 == 0 } // null
val list = listOf(1, 2, 3, 4, 5, 6)
//Splits original collection into pair of collections, where the first collection contains elements for which
the predicate returned true, while the second collection contains elements for which the predicate
returned false.
list.partition { it % 2 == 0 } //listOf(2, 4, 6), listOf(1, 3, 5)
//Returns a list containing all elements of the original collection and all elements of the given collection.
We can use the ‘+’ operator with it.
list + listOf(7, 8) //1, 2, 3, 4, 5, 6, 7, 8
//Returns a list of pairs built from the elements of both collections with the same indexes. The list has the
length of the shortest collection.
list.zip(listOf(7, 8)) //listOf(Pair(1, 7), Pair(2, 8))
Let’s get the magic going
OPERATORS COLLECTIONS MAGIC
ENOUGH SLIDES, code, Bs
LET’S CODE!
WE HAVE AN APP IN JAVA.
LET’S KOTLIN'IZE IT!
Hands on
Let’s rock and roll!
YES...
You can use the
“magic” option...
BUT...
That will only
generate ”Javified”
Kotlin code…
SO...
Do it, and then it’s
time to have real fun!
Do not forget
Each method you need to
implement/optimize is
almost every time a single
instruction.
Check the slides (41 to 52)..
THANKS!Any questions?
You can find us at @tallnato & @neteinstein
OTHER Things we missed
Higher-Order Functions and Lambdas
Inline functions
String templates
Properties
Class delegation
Java to Kotlin calls
Lambdas out of the box
val vs var
Apply
Sealed classes
Lazy & late init
Credits
Special thanks to all the people who made and
released these awesome resources for free:
× Presentation template by SlidesCarnival
× Photographs by Startupstockphotos

More Related Content

Similar to Kotlin 101 Workshop

Class DiagramIn the Assignment #10, you are given three files Ass.pdf
Class DiagramIn the Assignment #10, you are given three files Ass.pdfClass DiagramIn the Assignment #10, you are given three files Ass.pdf
Class DiagramIn the Assignment #10, you are given three files Ass.pdf
xlynettalampleyxc
 
Implement the additional 5 methods as indicated in the LinkedList fi.pdf
Implement the additional 5 methods as indicated in the LinkedList fi.pdfImplement the additional 5 methods as indicated in the LinkedList fi.pdf
Implement the additional 5 methods as indicated in the LinkedList fi.pdf
footstatus
 
Please complete all the code as per instructions in Java programming.docx
Please complete all the code as per instructions in Java programming.docxPlease complete all the code as per instructions in Java programming.docx
Please complete all the code as per instructions in Java programming.docx
cgraciela1
 
Write a function to merge two doubly linked lists. The input lists ha.pdf
Write a function to merge two doubly linked lists. The input lists ha.pdfWrite a function to merge two doubly linked lists. The input lists ha.pdf
Write a function to merge two doubly linked lists. The input lists ha.pdf
info706022
 
STAGE 2 The Methods 65 points Implement all the methods t.pdf
STAGE 2 The Methods 65 points Implement all the methods t.pdfSTAGE 2 The Methods 65 points Implement all the methods t.pdf
STAGE 2 The Methods 65 points Implement all the methods t.pdf
babitasingh698417
 
Implementation The starter code includes List.java. You should not c.pdf
Implementation The starter code includes List.java. You should not c.pdfImplementation The starter code includes List.java. You should not c.pdf
Implementation The starter code includes List.java. You should not c.pdf
maheshkumar12354
 
Complete code in Java The hashtable you'll be making will use String.pdf
Complete code in Java   The hashtable you'll be making will use String.pdfComplete code in Java   The hashtable you'll be making will use String.pdf
Complete code in Java The hashtable you'll be making will use String.pdf
aarifi9988
 
Hi,I have added the methods and main class as per your requirement.pdf
Hi,I have added the methods and main class as per your requirement.pdfHi,I have added the methods and main class as per your requirement.pdf
Hi,I have added the methods and main class as per your requirement.pdf
annaelctronics
 
The hashtable youll be making will use Strings as the keys and Obje.pdf
The hashtable youll be making will use Strings as the keys and Obje.pdfThe hashtable youll be making will use Strings as the keys and Obje.pdf
The hashtable youll be making will use Strings as the keys and Obje.pdf
vicky309441
 
File LinkedList.java Defines a doubly-l.pdf
File LinkedList.java Defines a doubly-l.pdfFile LinkedList.java Defines a doubly-l.pdf
File LinkedList.java Defines a doubly-l.pdf
Conint29
 
Write a program that will test a name) method no sorting routine from.docx
 Write a program that will test a name) method no sorting routine from.docx Write a program that will test a name) method no sorting routine from.docx
Write a program that will test a name) method no sorting routine from.docx
ajoy21
 
Groovy
GroovyGroovy
Groovy
Vijay Shukla
 
Note- Can someone help me with the private E get(int index- int curren (1).docx
Note- Can someone help me with the private E get(int index- int curren (1).docxNote- Can someone help me with the private E get(int index- int curren (1).docx
Note- Can someone help me with the private E get(int index- int curren (1).docx
VictorzH8Bondx
 
Describe an algorithm for concatenating two singly linked lists L and.pdf
Describe an algorithm for concatenating two singly linked lists L and.pdfDescribe an algorithm for concatenating two singly linked lists L and.pdf
Describe an algorithm for concatenating two singly linked lists L and.pdf
deepak596396
 
Problem- Describe an algorithm for concatenating two singly linked lis.pdf
Problem- Describe an algorithm for concatenating two singly linked lis.pdfProblem- Describe an algorithm for concatenating two singly linked lis.pdf
Problem- Describe an algorithm for concatenating two singly linked lis.pdf
JamesPXNNewmanp
 
Given below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.pdfGiven below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.pdf
info430661
 
Note- Can someone help me with the Public boolean add(E value) method.pdf
Note- Can someone help me with the Public boolean add(E value) method.pdfNote- Can someone help me with the Public boolean add(E value) method.pdf
Note- Can someone help me with the Public boolean add(E value) method.pdf
Stewart29UReesa
 
Below is a given ArrayList class and Main class Your Dreams Our Mission/tuto...
Below is a given ArrayList class and Main class  Your Dreams Our Mission/tuto...Below is a given ArrayList class and Main class  Your Dreams Our Mission/tuto...
Below is a given ArrayList class and Main class Your Dreams Our Mission/tuto...
davidwarner122
 
Jhtp5 20 Datastructures
Jhtp5 20 DatastructuresJhtp5 20 Datastructures
Jhtp5 20 Datastructuresmartha leon
 
The MyLinkedList class used in Listing 24.6 is a one-way directional .docx
 The MyLinkedList class used in Listing 24.6 is a one-way directional .docx The MyLinkedList class used in Listing 24.6 is a one-way directional .docx
The MyLinkedList class used in Listing 24.6 is a one-way directional .docx
Komlin1
 

Similar to Kotlin 101 Workshop (20)

Class DiagramIn the Assignment #10, you are given three files Ass.pdf
Class DiagramIn the Assignment #10, you are given three files Ass.pdfClass DiagramIn the Assignment #10, you are given three files Ass.pdf
Class DiagramIn the Assignment #10, you are given three files Ass.pdf
 
Implement the additional 5 methods as indicated in the LinkedList fi.pdf
Implement the additional 5 methods as indicated in the LinkedList fi.pdfImplement the additional 5 methods as indicated in the LinkedList fi.pdf
Implement the additional 5 methods as indicated in the LinkedList fi.pdf
 
Please complete all the code as per instructions in Java programming.docx
Please complete all the code as per instructions in Java programming.docxPlease complete all the code as per instructions in Java programming.docx
Please complete all the code as per instructions in Java programming.docx
 
Write a function to merge two doubly linked lists. The input lists ha.pdf
Write a function to merge two doubly linked lists. The input lists ha.pdfWrite a function to merge two doubly linked lists. The input lists ha.pdf
Write a function to merge two doubly linked lists. The input lists ha.pdf
 
STAGE 2 The Methods 65 points Implement all the methods t.pdf
STAGE 2 The Methods 65 points Implement all the methods t.pdfSTAGE 2 The Methods 65 points Implement all the methods t.pdf
STAGE 2 The Methods 65 points Implement all the methods t.pdf
 
Implementation The starter code includes List.java. You should not c.pdf
Implementation The starter code includes List.java. You should not c.pdfImplementation The starter code includes List.java. You should not c.pdf
Implementation The starter code includes List.java. You should not c.pdf
 
Complete code in Java The hashtable you'll be making will use String.pdf
Complete code in Java   The hashtable you'll be making will use String.pdfComplete code in Java   The hashtable you'll be making will use String.pdf
Complete code in Java The hashtable you'll be making will use String.pdf
 
Hi,I have added the methods and main class as per your requirement.pdf
Hi,I have added the methods and main class as per your requirement.pdfHi,I have added the methods and main class as per your requirement.pdf
Hi,I have added the methods and main class as per your requirement.pdf
 
The hashtable youll be making will use Strings as the keys and Obje.pdf
The hashtable youll be making will use Strings as the keys and Obje.pdfThe hashtable youll be making will use Strings as the keys and Obje.pdf
The hashtable youll be making will use Strings as the keys and Obje.pdf
 
File LinkedList.java Defines a doubly-l.pdf
File LinkedList.java Defines a doubly-l.pdfFile LinkedList.java Defines a doubly-l.pdf
File LinkedList.java Defines a doubly-l.pdf
 
Write a program that will test a name) method no sorting routine from.docx
 Write a program that will test a name) method no sorting routine from.docx Write a program that will test a name) method no sorting routine from.docx
Write a program that will test a name) method no sorting routine from.docx
 
Groovy
GroovyGroovy
Groovy
 
Note- Can someone help me with the private E get(int index- int curren (1).docx
Note- Can someone help me with the private E get(int index- int curren (1).docxNote- Can someone help me with the private E get(int index- int curren (1).docx
Note- Can someone help me with the private E get(int index- int curren (1).docx
 
Describe an algorithm for concatenating two singly linked lists L and.pdf
Describe an algorithm for concatenating two singly linked lists L and.pdfDescribe an algorithm for concatenating two singly linked lists L and.pdf
Describe an algorithm for concatenating two singly linked lists L and.pdf
 
Problem- Describe an algorithm for concatenating two singly linked lis.pdf
Problem- Describe an algorithm for concatenating two singly linked lis.pdfProblem- Describe an algorithm for concatenating two singly linked lis.pdf
Problem- Describe an algorithm for concatenating two singly linked lis.pdf
 
Given below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.pdfGiven below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.pdf
 
Note- Can someone help me with the Public boolean add(E value) method.pdf
Note- Can someone help me with the Public boolean add(E value) method.pdfNote- Can someone help me with the Public boolean add(E value) method.pdf
Note- Can someone help me with the Public boolean add(E value) method.pdf
 
Below is a given ArrayList class and Main class Your Dreams Our Mission/tuto...
Below is a given ArrayList class and Main class  Your Dreams Our Mission/tuto...Below is a given ArrayList class and Main class  Your Dreams Our Mission/tuto...
Below is a given ArrayList class and Main class Your Dreams Our Mission/tuto...
 
Jhtp5 20 Datastructures
Jhtp5 20 DatastructuresJhtp5 20 Datastructures
Jhtp5 20 Datastructures
 
The MyLinkedList class used in Listing 24.6 is a one-way directional .docx
 The MyLinkedList class used in Listing 24.6 is a one-way directional .docx The MyLinkedList class used in Listing 24.6 is a one-way directional .docx
The MyLinkedList class used in Listing 24.6 is a one-way directional .docx
 

Recently uploaded

Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
Tier1 app
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
e20449
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
AMB-Review
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
Tendenci - The Open Source AMS (Association Management Software)
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
informapgpstrackings
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Mind IT Systems
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
WSO2
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Natan Silnitsky
 

Recently uploaded (20)

Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 

Kotlin 101 Workshop

  • 1.
  • 2. Please open the following URLs: This presentation: https://goo.gl/1teY4Q Code repo: https://goo.gl/GY9Fgn
  • 4. Hello!I am Renato Almeida You can find me at @tallnato (on the places I fit) Because I am big, like BIG
  • 5. Hello!I am Pedro Vicente You can find me at @neteinstein (all over the place) … and I’m the beautiful one of this talk!
  • 6. Yeah, that company from Oporto that works in self-organization Mindera
  • 7. This is a tale of our experience!
  • 8. Our team moved 99% of our codebase to kotlin
  • 9. 1. Why kotlin And not just stick with Java?
  • 10.
  • 11. × Java’s null-unsafety !!!!!!!!!!!!!!!!!!!!!!!!!!! × Android doesn’t have the new bells and whistles of Java (8+) × Java’s base is procedural, not functional Why NOT JAVA
  • 12. × Kotlin is 100% interoperable with Java × Yes, really. × Kotlin isn’t as verbose × Everybody knows… the less code, the less bugs × Kotlin is fun (pun intended) × And we have var and val, let, apply…. Why kotlin
  • 13. × Extensions! × Very fast learning curve × You can do magic with it, no, for real! Why kotlin
  • 14. × Kotlin Standard Library adds 800Kb to the .apk × Kotlin is from Russia. You need Vodka. × Ok... it’s just the first one. Drawbacks
  • 15.
  • 17. Kotlin types CREDITS TO: https://github.com/JetBrains/kotlin-workshop
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 30.
  • 31. RememberYou can use automatic conversion… but if you aren’t using the fun stuff on Kotlin… what’s the .?
  • 32.
  • 33. Let’s get the magic going OPERATORS COLLECTIONS MAGIC
  • 34. Kotlin operators CREDITS TO: https://github.com/JetBrains/kotlin-workshop
  • 35. Kotlin operators CREDITS TO: https://github.com/JetBrains/kotlin-workshop
  • 36. Kotlin operators CREDITS TO: https://github.com/JetBrains/kotlin-workshop
  • 37. Kotlin operators CREDITS TO: https://github.com/JetBrains/kotlin-workshop
  • 38. Kotlin operators CREDITS TO: https://github.com/JetBrains/kotlin-workshop
  • 39. Kotlin operators CREDITS TO: https://github.com/JetBrains/kotlin-workshop
  • 40. Let’s get the magic going OPERATORS COLLECTIONS MAGIC
  • 41. val list = listOf(1, 2, 3, 4, 5, 6) //Returns true if at least one element matches the given predicate. list.any { it % 2 == 0 } //TRUE list.any { it > 10 } // FALSE //Returns true if all match the given predicate list.all { it < 10 } //TRUE list.all { it % 2 == 0 } //FALSE //Returns the number of elements matching the given predicate. list.count { it % 2 == 0 } // 3
  • 42. val list = listOf(1, 2, 3, 4, 5, 6) //Accumulates the value: starts with initial value //and applies an operation from the first to the last element in a collection. list.fold(4) { total, next -> total + next } //25 //Same as fold, but goes from the last element to first list.foldRight(4) { total, next -> total + next } //25 //Same as fold without initial value list.reduce { total, next -> total + next } //21 //Same as foldRight without initial value list.reduceRight { total, next -> total + next } //21
  • 43. val list = listOf(1, 2, 3, 4, 5, 6) //No comments list.forEach { println(it) } //Also, no comments list.forEachIndexed { index, value -> println("position $index contains a $value") } //Returns Max, the dog list.max() // 6 //Returns Minion list.min() // 1
  • 44. val list = listOf(1, 2, 3, 4, 5, 6) //Returns the first element yielding the largest value of the given function or null if there are no elements. list.maxBy { -it } //1 //Same logic for min list.minBy { -it } //6 //If none of the elements matches condition list.none { it % 7 == 0 } //TRUE //Returns the sum of all values produced by the transform function from the elements in the collection list.sumBy { it % 2 } //3
  • 45. val list = listOf(1, 2, 3, 4, 5, 6) //Returns a list containing all elements except first n elements. list.drop(4) //5, 6 //Returns a list containing all elements except first elements that satisfy the given predicate. list.dropWhile { it < 3 } //3, 4, 5, 6 //Returns a list containing all elements except last elements that satisfy the given predicate. list.dropLastWhile { it > 4 } //1, 2, 3, 4 //Returns a list containing all elements matching the given predicate. list.filter { it % 2 == 0 } //2, 4, 6 //Returns a list containing all elements not matching the given predicate. list.filterNot { it % 2 == 0 } //1, 3, 5
  • 46. val list = listOf(1, 2, 3, 4, 5, 6) //Returns a list containing elements at specified indices. list.slice(listOf(1, 3, 4)) //2, 4, 5 //Returns a list containing first n elements list.take(2) //1, 2 //Returns a list containing last n elements. list.takeLast(2) //5, 6 //Returns a list containing first elements satisfying the given predicate. list.takeWhile { it < 3 } //1, 2
  • 47. val list = listOf(1, 2, 3, 4, 5, 6) //Returns a list containing the results of applying //the given transform function to each element and //its index of the original collection. list.mapIndexed { index, it -> index * it } //Returns true if the element is found in the collection. list.contains(2) // TRUE //Returns an element at the given index or throws an //IndexOutOfBoundsException if the index is out //of bounds of this collection. list.elementAt(1) //2
  • 48. val list = listOf(1, 2, 3, 4, 5, 6) //Iterates over the elements creating a new collection for each one, //and finally flattens all the collections into a unique list containing all the elements. list.flatMap { listOf(it, it + 1) } //1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7 //Returns a map of the elements in original collection grouped by the result of given function list.groupBy { if (it % 2 == 0) "even" else "odd" }//mapOf("odd" to listOf(1, 3, 5), "even" to listOf(2, 4, 6)), 2 //Returns a list containing the results of applying the given transform function to each element of the original collection. list.map { it * 2 } //2, 4, 6, 8, 10, 12
  • 49. val list = listOf(1, 2, 3, 4, 5, 6) //Returns an element at the given index or the result of calling the default function if the index is out of bounds of this collection. list.elementAtOrElse(10, { 2 * it }) //20 //Returns an element at the given index or null if the index is out of bounds of this collection. list.elementAtOrNull(10) // null //Returns an element at the given index or throws an IndexOutOfBoundsException if the index is out of bounds of this collection. list.elementAt(1) //2 //Returns an element at the given index or the result of calling the default function if the index is out of bounds of this collection. list.elementAtOrElse(10, { 2 * it }) //20
  • 50. val list = listOf(1, 2, 3, 4, 5, 6) //Returns an element at the given index or null if the index is out of bounds of this collection. list.elementAtOrNull(10) // null //Returns the first element matching the given predicate , or null if no element was found. list.firstOrNull { it % 7 == 0 } //null //Returns the first index of element, or -1 if the collection does not contain element. list.indexOf(4) //3 //Returns index of the first element matching the given predicate, or -1 if the collection does not contain such element. list.indexOfFirst { it % 2 == 0 } //1
  • 51. val list = listOf(1, 2, 3, 4, 5, 6)//Returns index of the last element matching the given predicate, or -1 if the collection does not contain such element. list.indexOfLast { it % 2 == 0 } //5 //Returns the last element matching the given predicate. list.last { it % 2 == 0 } // 6 //Returns the single element matching the given predicate, or throws exception if there is no or more than one matching element. list.single { it % 5 == 0 } // 5 //Returns the single element matching the given predicate, or null if element was not found or more than one element was found. list.singleOrNull { it % 7 == 0 } // null
  • 52. val list = listOf(1, 2, 3, 4, 5, 6) //Splits original collection into pair of collections, where the first collection contains elements for which the predicate returned true, while the second collection contains elements for which the predicate returned false. list.partition { it % 2 == 0 } //listOf(2, 4, 6), listOf(1, 3, 5) //Returns a list containing all elements of the original collection and all elements of the given collection. We can use the ‘+’ operator with it. list + listOf(7, 8) //1, 2, 3, 4, 5, 6, 7, 8 //Returns a list of pairs built from the elements of both collections with the same indexes. The list has the length of the shortest collection. list.zip(listOf(7, 8)) //listOf(Pair(1, 7), Pair(2, 8))
  • 53. Let’s get the magic going OPERATORS COLLECTIONS MAGIC
  • 54. ENOUGH SLIDES, code, Bs LET’S CODE! WE HAVE AN APP IN JAVA. LET’S KOTLIN'IZE IT!
  • 56. YES... You can use the “magic” option...
  • 57. BUT... That will only generate ”Javified” Kotlin code…
  • 58. SO... Do it, and then it’s time to have real fun!
  • 59.
  • 60. Do not forget Each method you need to implement/optimize is almost every time a single instruction. Check the slides (41 to 52)..
  • 61.
  • 62. THANKS!Any questions? You can find us at @tallnato & @neteinstein
  • 63. OTHER Things we missed Higher-Order Functions and Lambdas Inline functions String templates Properties Class delegation Java to Kotlin calls Lambdas out of the box val vs var Apply Sealed classes Lazy & late init
  • 64. Credits Special thanks to all the people who made and released these awesome resources for free: × Presentation template by SlidesCarnival × Photographs by Startupstockphotos