-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
More puzzlers #23
Comments
angryziber
added a commit
that referenced
this issue
Aug 13, 2017
Here is one more puzzler from kotlin slack https://github.com/dkandalov/kotlin-puzzlers/blob/master/puzzlers/x-child-apply.kts: open class Node(val name: String) {
fun lookup() = "lookup in: $name"
}
class Example : Node("container") {
fun createChild(name: String): Node? = Node(name)
val child1 = createChild("child1")?.apply {
println("child1 ${lookup()}")
}
val child2 = createChild("child2").apply {
println("child2 ${lookup()}")
}
}
Example() |
angryziber
added a commit
that referenced
this issue
Oct 13, 2017
fun process(num: Int) = if (num % 2 == 0) {
print("$num,")
true
} else {
false
}
val arr = arrayOf(0, 1, 2, 3, 4, 5)
val result = arr.fold(true) { acc, num ->
acc && process(num)
}
println(result) What will be printed? |
angryziber
added a commit
that referenced
this issue
Sep 30, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
FYI I created this repo https://github.com/dkandalov/kotlin-puzzlers which includes some of the puzzlers from this repo and some new puzzlers. In particular these two might be interesting:
where
when
needs to be an expression in order to be exhaustive, e.g.:where
Color.from
is extension method on instances of enum, not on the enum class. For this to work enum needs companion object and semicolon:The text was updated successfully, but these errors were encountered: