Created
June 8, 2022 07:14
-
-
Save uzilan/06a41ff6116907a389294263cb4bba5c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package packages | |
import kotlin.random.Random | |
data class Stamp(val price: Double) | |
data class Package(val address: String, var stamp: Stamp? = null) { | |
fun unpack(): Any = TODO("Not yet implemented") | |
} | |
object MailService { | |
fun sendPackage(pack: Package): Package { | |
TODO("Not yet implemented") | |
} | |
} | |
fun applyExample() { | |
val address = "Someone somewhere 12345" | |
val pack = Package(address) | |
.apply { this.stamp = Stamp(50.0) } | |
MailService.sendPackage(pack) | |
} | |
fun runExample() { | |
val address = "Someone somewhere 12345" | |
val stamp = Stamp(50.0) | |
val brokenPackage = Package(address, stamp) | |
val pack = brokenPackage.run { | |
Package(this.address, this.stamp) | |
} | |
MailService.sendPackage(pack) | |
} | |
fun alsoExample() { | |
val address = "Someone somewhere 12345" | |
val stamp = Stamp(50.0) | |
val pack = Package(address, stamp) | |
MailService.sendPackage(pack).also { | |
informCustomer(it.address) | |
} | |
} | |
fun letExample() { | |
val content = openPackage()?.let { | |
registerAddress(it.address) | |
it.unpack() | |
} ?: "nothing in there" | |
playAroundWith(content) | |
} | |
fun registerAddress(address: String) { | |
TODO("Not yet implemented") | |
} | |
fun playAroundWith(content: Any) { | |
TODO("Not yet implemented") | |
} | |
fun informCustomer(address: String) { | |
TODO("Not yet implemented") | |
} | |
fun openPackage(): Package? { | |
return if (Random.nextBoolean()) | |
Package("Someone somewhere 12345") | |
else null | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment