From 504335dd30384baa3f5d84ba0dc38406a851fc02 Mon Sep 17 00:00:00 2001 From: Zainab 27 Date: Sat, 15 Feb 2025 16:33:59 +0300 Subject: [PATCH 1/6] Doubled numbers --- LambdaCollectionsTask/LambdaCollectionsTask.iml | 15 +++++++++++++++ LambdaCollectionsTask/src/ListTransformation.kt | 5 +++++ 2 files changed, 20 insertions(+) create mode 100644 LambdaCollectionsTask/LambdaCollectionsTask.iml create mode 100644 LambdaCollectionsTask/src/ListTransformation.kt diff --git a/LambdaCollectionsTask/LambdaCollectionsTask.iml b/LambdaCollectionsTask/LambdaCollectionsTask.iml new file mode 100644 index 0000000..4fd7bdb --- /dev/null +++ b/LambdaCollectionsTask/LambdaCollectionsTask.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/LambdaCollectionsTask/src/ListTransformation.kt b/LambdaCollectionsTask/src/ListTransformation.kt new file mode 100644 index 0000000..ef73c25 --- /dev/null +++ b/LambdaCollectionsTask/src/ListTransformation.kt @@ -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) +} \ No newline at end of file From 188e84a5f5188df45dc82a3d911ca66d6318a334 Mon Sep 17 00:00:00 2001 From: Zainab 27 Date: Sat, 15 Feb 2025 16:51:59 +0300 Subject: [PATCH 2/6] Filtering names --- LambdaCollectionsTask/src/StringswithLambda.kt | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 LambdaCollectionsTask/src/StringswithLambda.kt diff --git a/LambdaCollectionsTask/src/StringswithLambda.kt b/LambdaCollectionsTask/src/StringswithLambda.kt new file mode 100644 index 0000000..635f7bf --- /dev/null +++ b/LambdaCollectionsTask/src/StringswithLambda.kt @@ -0,0 +1,11 @@ +fun main() { + val names = listOf("Alice", "Bob", "Amir", "Charlie", "Annie", "David") + + fun filterNames(names: List, condition: (String) -> Boolean): List { + return names.filter(condition) + } + + val filteredNames = filterNames(names) { it.startsWith("A") } + + println(filteredNames) +} \ No newline at end of file From d5f22f4b403cf0c5d723a9042157b950d419e167 Mon Sep 17 00:00:00 2001 From: Zainab 27 Date: Sat, 15 Feb 2025 17:04:52 +0300 Subject: [PATCH 3/6] Sorted by Descending --- LambdaCollectionsTask/src/CustomLambda.kt | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 LambdaCollectionsTask/src/CustomLambda.kt diff --git a/LambdaCollectionsTask/src/CustomLambda.kt b/LambdaCollectionsTask/src/CustomLambda.kt new file mode 100644 index 0000000..bd71b59 --- /dev/null +++ b/LambdaCollectionsTask/src/CustomLambda.kt @@ -0,0 +1,5 @@ +fun main (){ + val fruits = listOf ("apple","banana","kiwi","strawberry","grape") + val sortedFruits = fruits.sortedByDescending {it.length} + println(sortedFruits) +} \ No newline at end of file From 720348c6c7147845f59c35e0126920645fc36ff5 Mon Sep 17 00:00:00 2001 From: Zainab 27 Date: Sat, 15 Feb 2025 17:11:59 +0300 Subject: [PATCH 4/6] Customizing a list filter --- LambdaCollectionsTask/src/FilterofaList.kt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 LambdaCollectionsTask/src/FilterofaList.kt diff --git a/LambdaCollectionsTask/src/FilterofaList.kt b/LambdaCollectionsTask/src/FilterofaList.kt new file mode 100644 index 0000000..0c6b9ae --- /dev/null +++ b/LambdaCollectionsTask/src/FilterofaList.kt @@ -0,0 +1,14 @@ +fun main() { + fun customFilter(numbers: List, filter: (Int) -> Boolean): List { + 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) +} From f06a46ca59a73c210ce6968ef914d9c400ebae99 Mon Sep 17 00:00:00 2001 From: Zainab 27 Date: Sat, 15 Feb 2025 17:16:13 +0300 Subject: [PATCH 5/6] Combining lambdas to process numbers --- LambdaCollectionsTask/src/CombiningLambdas.kt | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 LambdaCollectionsTask/src/CombiningLambdas.kt diff --git a/LambdaCollectionsTask/src/CombiningLambdas.kt b/LambdaCollectionsTask/src/CombiningLambdas.kt new file mode 100644 index 0000000..94b8c7c --- /dev/null +++ b/LambdaCollectionsTask/src/CombiningLambdas.kt @@ -0,0 +1,9 @@ +fun main() { + fun processNumbers(numbers: List): List { + 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) +} From efb0be43a3c63f13431473647077d81f28d15796 Mon Sep 17 00:00:00 2001 From: Zainab 27 Date: Sat, 15 Feb 2025 17:18:00 +0300 Subject: [PATCH 6/6] Lambdas and collections --- LambdaCollectionsTask/src/Main.kt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 LambdaCollectionsTask/src/Main.kt diff --git a/LambdaCollectionsTask/src/Main.kt b/LambdaCollectionsTask/src/Main.kt new file mode 100644 index 0000000..7265465 --- /dev/null +++ b/LambdaCollectionsTask/src/Main.kt @@ -0,0 +1,14 @@ +//TIP To Run code, press or +// click the icon in the gutter. +fun main() { + val name = "Kotlin" + //TIP Press 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 to start debugging your code. We have set one breakpoint + // for you, but you can always add more by pressing . + println("i = $i") + } +} \ No newline at end of file