Skip to content

Instantly share code, notes, and snippets.

View vamsitallapudi's full-sized avatar
🚩
Become better than yesterday

Vamsi Tallapudi vamsitallapudi

🚩
Become better than yesterday
View GitHub Profile
//Lambda Expression
val areaOfRectangle = { length: Int, breadth: Int -> (length * breadth) }
fun main() {
areaOfRectangle(10,20)
}
//simplified version
val areaOfRectangleSimplified: (Int, Int) -> Int = { length, breadth -> length * breadth }
fun main() {
areaOfRectangleSimplified(30,40)
}
val list = listOf(1, 3, 5, 7, 9)
// fold function is taking a parameter and a lambda expression
println(list.fold(1, { a, b -> a * b }))
val list = listOf(1, 3, 5, 7, 9)
// if the lambda expression is the last parameter, we can move the parameter out
println(list.fold(1) { a, b -> a * b })
val list = listOf(1, 3, 5, 7, 9)
// a function taking a single function as a parameter
list.forEach({ println(it) }) //it -> iterator which iterates and gives each value of list
// if parameter is a single lambda expression, we can omit the paranthesis
list.forEach { println() }
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorAccent"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.coderefer.uploadfiletoserver.MainActivity">
<TextView