Higher-order function

The order of a function is the nesting depth of function arrows:

  • Order 0—values, for instance, 1, false or "hello"
  • Order 1—functions A => B, for instance def addOne: Int => Int = x => x + 1
  • Order 2—higher-order functions A => B => C, for instance:
def map: Vector[Int] => (Int => Int) => Vector[Int] = 
xs => f => xs.map(f)
  • Order 3—higher-order functions A => B => C => D

Any function of an order strictly greater than 1 is a higher-order function.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset