diff --git a/.idea/modules.xml b/.idea/modules.xml index 54b9186..7335cc1 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -3,6 +3,7 @@ + \ No newline at end of file diff --git a/lamdas/lamdas.iml b/lamdas/lamdas.iml new file mode 100644 index 0000000..4fd7bdb --- /dev/null +++ b/lamdas/lamdas.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/lamdas/src/Main.kt b/lamdas/src/Main.kt new file mode 100644 index 0000000..b2783b0 --- /dev/null +++ b/lamdas/src/Main.kt @@ -0,0 +1,26 @@ +fun main() { + greetSeaCreatures() + println(findPearl(6)) + println(divideTreasure(1000.0,5)) + val result = calculateDepth(1500, 800) {depth1, depth2 -> if (depth1 > depth2) depth1 - depth2 else depth2 - depth1} + println(result) //added an if statement to ensure result is always positive + println(diveMessage("deep sea")) +} + + +val greetSeaCreatures = { println("Hello, Deep Sea Adventurer!")} + +val findPearl: (Int) -> Int = { x -> x * x } + +val divideTreasure = {total: Double, explorers: Int -> total / explorers} + +fun calculateDepth(depth1: Int, depth2: Int, difference: (Int, Int) -> Int): Int { + return difference(depth1, depth2) +} + +fun String.loud(): String { + return this.uppercase() + "!" +} + +val diveMessage = {text: String -> text.loud()} +