Skip to content

Instantly share code, notes, and snippets.

@pradhuman7d1
Created December 15, 2021 08:36
Show Gist options
  • Save pradhuman7d1/f870e21851f8c987794c1000b9f76d05 to your computer and use it in GitHub Desktop.
Save pradhuman7d1/f870e21851f8c987794c1000b9f76d05 to your computer and use it in GitHub Desktop.
scala-functions
Q. What is unit return type?
A. unit is used whenever we don't need to return a value.
Q. val p = pow _ ; what is p storing here?
A. p is storing the function pow and this is an example of higher order functions.
Q. What are closures?
A. Closures are special functions that can access and use values declared outside of it.
Q. What are anonymous functions?
A. Functions that does not contains any name and are short to declare. Used when we need functions inline.
Q. What is the keyword to declare a function?
a. fn
b. fun
c. dec
d. def
A. d. def
Q. val p = pow _ ; what this _ signifies?
a. return nothing (unit)
b. return answer
c. return function
d. return power of p
A. c. return function
Q. The following code is an example of ?
val p = 10
def example(a:double) = a*p / 100
a. Anonymous Function
b. Higher Order Function
c. Closure
d. none of these
A. c. Closure
Q. What is the correct syntax to declare variable arguments in a function?
a. (args: Int)
b. (args...)
c. (varargs)
d. (args: Int*)
A. d. (args: Int*)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment