SlideShare a Scribd company logo
1 of 64
Download to read offline
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.pdfxlynettalampleyxc
 
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.pdffootstatus
 
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.docxcgraciela1
 
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.pdfinfo706022
 
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.pdfbabitasingh698417
 
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.pdfmaheshkumar12354
 
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.pdfaarifi9988
 
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.pdfannaelctronics
 
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.pdfvicky309441
 
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.pdfConint29
 
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.docxajoy21
 
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).docxVictorzH8Bondx
 
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.pdfdeepak596396
 
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.pdfJamesPXNNewmanp
 
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.pdfinfo430661
 
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.pdfStewart29UReesa
 
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 .docxKomlin1
 

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

Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 

Recently uploaded (20)

Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 

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