Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions LambdaCollectionsTask/LambdaCollectionsTask.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/testResources" type="java-test-resource" />
</content>
<orderEntry type="jdk" jdkName="openjdk-23" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
</component>
</module>
9 changes: 9 additions & 0 deletions LambdaCollectionsTask/src/CombiningLambdas.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
fun main() {
fun processNumbers(numbers: List<Int>): List<Int> {
return numbers.filter { it % 2 != 0 }
.map { it * it }
}

val result = processNumbers(listOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10))
println(result)
}
5 changes: 5 additions & 0 deletions LambdaCollectionsTask/src/CustomLambda.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
fun main (){
val fruits = listOf ("apple","banana","kiwi","strawberry","grape")
val sortedFruits = fruits.sortedByDescending {it.length}
println(sortedFruits)
}
14 changes: 14 additions & 0 deletions LambdaCollectionsTask/src/FilterofaList.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
fun main() {
fun customFilter(numbers: List<Int>, filter: (Int) -> Boolean): List<Int> {
return numbers.filter(filter)
}

val result1 = customFilter(listOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)) { it > 5 }
println(result1)

val result2 = customFilter(listOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)) { it % 2 == 0 }
println(result2)

val result3 = customFilter(listOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)) { it % 3 == 0 }
println(result3)
}
5 changes: 5 additions & 0 deletions LambdaCollectionsTask/src/ListTransformation.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
fun main () {
val numbers = listOf (1,2,3,4,5,6,7,8,9,10)
val doubledNumbers = numbers.map {it*2}
println(doubledNumbers)
}
14 changes: 14 additions & 0 deletions LambdaCollectionsTask/src/Main.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
fun main() {
val name = "Kotlin"
//TIP Press <shortcut actionId="ShowIntentionActions"/> with your caret at the highlighted text
// to see how IntelliJ IDEA suggests fixing it.
println("Hello, " + name + "!")

for (i in 1..5) {
//TIP Press <shortcut actionId="Debug"/> to start debugging your code. We have set one <icon src="AllIcons.Debugger.Db_set_breakpoint"/> breakpoint
// for you, but you can always add more by pressing <shortcut actionId="ToggleLineBreakpoint"/>.
println("i = $i")
}
}
11 changes: 11 additions & 0 deletions LambdaCollectionsTask/src/StringswithLambda.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
fun main() {
val names = listOf("Alice", "Bob", "Amir", "Charlie", "Annie", "David")

fun filterNames(names: List<String>, condition: (String) -> Boolean): List<String> {
return names.filter(condition)
}

val filteredNames = filterNames(names) { it.startsWith("A") }

println(filteredNames)
}