scala abstraction

A context parameter is a parameter which a method or a function picks up from the current scope context. These parameters are not usually passed to them. Compiler can synthesise repetitive parameters instead of programmer writing them by themselves.

For example

def A(using a: Int): Int =
    B
def B(using a: Int): Int =
    a
 
A(using 4)
// returns 4

What happens here? using keyword declares a context parameter. We provide context parameter to method A but it doesn’t require to pass it to method B. B takes the context parameter from the current scope (scope of the called method).

Anonymous context parameter

In method A, we won’t even require to name context parameter. We can just specify data type.

def A(using Int): Int =
    B