From the course: Scala Essential Training for Data Science (2017)
Unlock this course with a free trial
Join today to access over 25,300 courses taught by industry experts.
Scala functions - Scala Tutorial
From the course: Scala Essential Training for Data Science (2017)
Scala functions
- [Instructor] Lets talk about scala functions. I've started the Scala REPL here. Now scala functions are expressions that can be called with parameters to compute a value. If you've worked with other programming languages that use functions, you've probably worked with a syntax that allows you to define a function, give it a name, and optionally pass in some parameters. We can do this in Scala as well. Let's look at the structure. We use the def keyword to define a function. Give it a name like myFunction, and tell it what parameters we want to pass in, like the variable a, which is a type integer, and b, which is also a type integer. Then I want to indicate that this function is going to return a particular value. In this case, it'll return an integer. And I want to compute a new value within this function called c, and c is going to be the value a times b. Then I simply want to return a value of c. Then I will close off my definition and now I have my function. Now once we've…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
The advantages of Scala for data science1m 34s
-
(Locked)
Installing Scala2m 56s
-
(Locked)
Scala data types4m 34s
-
(Locked)
Scala collections1m 17s
-
(Locked)
Scala sets Scala arrays, vectors, and ranges5m 37s
-
(Locked)
Scala maps4m 28s
-
(Locked)
Scala expressions3m 40s
-
(Locked)
Scala functions2m 46s
-
(Locked)
Scala objects8m 5s
-
-
-
-
-
-