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/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) +} 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 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) +} 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 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 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