scala implicit (2)

context bound

Context bound is a shorthand syntax expressing a type parameter is bounded by a type. It implies a context parameter comes along with the method.

// A list can be sorted when its elem A can be ordered
// use implicitly[Ordering[A] to get the context paramter
def sort[A: Ordering](list: List[A]): List[A] = ???

Method sort is a polymorphic method or a generic method.

A is the type parameter. Ordering is the bound of A. It implies a context parameter Ordering[A] follows the parameter list.

def sort(list: List[A])(implicit order: Ordering[A]): List[A] = ???