Functions in Scala
Scala supports both named and anonymous functions. Here's an example of a named function:
kotlin
def add(x: Int, y: Int): Int = {
return x + y
}
val result = add(2, 3) // result is now 5
And here's an example of an anonymous function:
kotlin
val add = (x: Int, y: Int) => x + y
val result = add(2, 3) // result is now 5
No comments:
Post a Comment