lOMoARcPSD| 61552889
ĐẠI HỌC BÁCH KHOA HÀ NỘI
lOMoARcPSD| 61552889
Trường Công nghệ thông n và Truyền thông
O CÁO LESSION 2
Môn: Phát triển ứng dụng cho thiết bị di ộng – IT4785 Mã
lớp: 151902
Giảng viên hướng dẫn : Thy Nguyễn Hồng Quang
Họ và tên – MSSV : Nguyễn Văn Minh - 20215092
Contents
1. Explore the main() funcon ........................................................................................ 3
2. Learn why (almost) everything has a value ................................................................. 4
3. Learn more about funcons ....................................................................................... 5
4. Explore default values and compact funcons ........................................................... 7
5. Get started with lters ................................................................................................ 8
6. Get started with lambdas and higher-order funcons .............................................. 10
7. Summary .................................................................................................................. 11
lOMoARcPSD| 61552889
1. Explore the main() funcon
lOMoARcPSD| 61552889
2. Learn why (almost) everything has a value
lOMoARcPSD| 61552889
3. Learn more about funcons
lOMoARcPSD| 61552889
lOMoARcPSD| 61552889
4. Explore default values and compact funcons
lOMoARcPSD| 61552889
5. Get started with lters
lOMoARcPSD| 61552889
lOMoARcPSD| 61552889
6. Get started with lambdas and higher-order funcons
lOMoARcPSD| 61552889
7. Summary
To create new Kotlin source les in IntelliJ IDEA, click on "src" in the Project pane and right-click to bring up
a menu. Select "New->Kotlin File/Class".
To compile and run a program in IntelliJ IDEA, click the green triangle next to the funcon. Output appears
in a window below.main()
In IntelliJ IDEA, specify command line arguments to pass to the funcon in Run > Edit Conguraons.main()
Almost everything in Kotlin has a value. You can use this fact to make your code more concise by using the
value of an or as an expression or return value.ifwhen
Default arguments remove the need for mulple versions of a funcon or method. For example: fun
swim(speed: String = "fast") { ... }
Compact funcons, or single-expression funcons, can make your code more readable. For example: fun
isTooHot(temperature: Int) = temperature > 30
You've learned some basics about lters, which use lambda expressions. For example: val beginsWithP =
decoraons.lter { it [0] == 'p' }
A lambda expression is a funcon that is not bound to an idener, i.e. it is an anonymous funcon.
Lambda expressions are dened between curly braces .{}
lOMoARcPSD| 61552889
In a higher-order funcon, you pass a funcon such as a lambda expression to another funcon as data.
For example: dirtyLevel = updateDirty(dirtyLevel) { dirtyLevel -> dirtyLevel + 23}

Preview text:

lOMoAR cPSD| 61552889
ĐẠI HỌC BÁCH KHOA HÀ NỘI lOMoAR cPSD| 61552889
Trường Công nghệ thông tin và Truyền thông BÁO CÁO LESSION 2
Môn: Phát triển ứng dụng cho thiết bị di ộng – IT4785 Mã lớp: 151902 Giảng viên hướng dẫn : Thầy Nguyễn Hồng Quang Họ và tên – MSSV : Nguyễn Văn Minh - 20215092 Contents
1. Explore the main() function ........................................................................................ 3
2. Learn why (almost) everything has a value ................................................................. 4
3. Learn more about functions ....................................................................................... 5
4. Explore default values and compact functions ........................................................... 7
5. Get started with filters ................................................................................................ 8
6. Get started with lambdas and higher-order functions .............................................. 10
7. Summary .................................................................................................................. 11 lOMoAR cPSD| 61552889
1. Explore the main() function lOMoAR cPSD| 61552889
2. Learn why (almost) everything has a value lOMoAR cPSD| 61552889 3. Learn more about functions lOMoAR cPSD| 61552889 lOMoAR cPSD| 61552889
4. Explore default values and compact functions lOMoAR cPSD| 61552889 5. Get started with filters lOMoAR cPSD| 61552889 lOMoAR cPSD| 61552889
6. Get started with lambdas and higher-order functions lOMoAR cPSD| 61552889 7. Summary •
To create new Kotlin source files in IntelliJ IDEA, click on "src" in the Project pane and right-click to bring up
a menu. Select "New->Kotlin File/Class". •
To compile and run a program in IntelliJ IDEA, click the green triangle next to the function. Output appears in a window below.main() •
In IntelliJ IDEA, specify command line arguments to pass to the function in Run > Edit Configurations.main() •
Almost everything in Kotlin has a value. You can use this fact to make your code more concise by using the
value of an or as an expression or return value.ifwhen •
Default arguments remove the need for multiple versions of a function or method. For example: fun
swim(speed: String = "fast") { ... } •
Compact functions, or single-expression functions, can make your code more readable. For example: fun
isTooHot(temperature: Int) = temperature > 30 •
You've learned some basics about filters, which use lambda expressions. For example: val beginsWithP =
decorations.filter { it [0] == 'p' } •
A lambda expression is a function that is not bound to an identifier, i.e. it is an anonymous function.
Lambda expressions are defined between curly braces .{} lOMoAR cPSD| 61552889 •
In a higher-order function, you pass a function such as a lambda expression to another function as data.
For example: dirtyLevel = updateDirty(dirtyLevel) { dirtyLevel -> dirtyLevel + 23}