What does it mean?

From book ‘Programming in Scala’:

Functions that are first-class values provide a convenient means for abstracting
over operations and creating new control structures. This generalization
of functions provides great expressiveness.

What this block means at very low level?Basically how to explain meaning of this block to programmers from non functional background, particularly first sentence?

This sentence means that the return value of functions is equal the value of the type of Int, Float, String and so on. So you can pass a function as a argument to another function. We call a function first-order function if it doesn’t receive any function as arguments, otherwise, we call it high-order function.

It means you can easily create function objects and use the in expressions that effectively work like if-statements, loops, etc.

**scala> val itIsEven: Int => Boolean = _ % 2 == 0
itIsEven: Int => Boolean = $$Lambda$1022/1792711692@7412ed6b

(1 to 10).filter(itIsEven).foreach(i => println(s"$i is even"))
2 is even
4 is even
6 is even
8 is even
10 is even**

1 Like