3.5 Functional Programming
Functions as Objects
- Functions in Scala are first-class objects. That means we can assign a function to a
val
and pass it to classes, objects, or other functions as an argument.
1 | // These are normal functions. |
val vs. def
- (?) Why would you want to create a
val
instead of adef
? With aval
, you can now pass the function around to other functions.
1 | // create our function |
- Functions are evaluated every time they are called, while vals are evaluated at instantiation.
1 | import scala.util.Random |
FIR Filter with Window Function Passed
- window function
1 | // get some math functions |
- FIR
1 | // our FIR has parameterized window length, IO bitwidth, and windowing function |