DEV Community

Enrque\m/Talavera
Enrque\m/Talavera

Posted on

chapter 21,chapter22

Functions literals can be assigned to val fields to create function variables.
To be consistent with algebra and other FP resources, I refer to these fields are variables rather than values.
Examples of the val function syntax.
A function is an instance of a FunctionN trait, such as Function1, or Function2.
What various function type signatures look like in the REPL.
How to treat a function as a variable by putting it in a Map.
That, in general you can use a function variable just like any other variable.

A def mehtod is not a val (Part I)
A def mehtod is not a variable(Part II)
val =>creates an instance of the Function1 trait
def => create method

Convert def method to function.
def double(i:Int) = i*2

val doubleF = double _

Top comments (0)