Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Learning Jupyter 5

You're reading from   Learning Jupyter 5 Explore interactive computing using Python, Java, JavaScript, R, Julia, and JupyterLab

Arrow left icon
Product type Paperback
Published in Aug 2018
Publisher
ISBN-13 9781789137408
Length 282 pages
Edition 2nd Edition
Languages
Tools
Arrow right icon
Toc

Table of Contents (18) Chapters Close

Title Page
Packt Upsell
Contributors
Preface
1. Introduction to Jupyter FREE CHAPTER 2. Jupyter Python Scripting 3. Jupyter R Scripting 4. Jupyter Julia Scripting 5. Jupyter Java Coding 6. Jupyter JavaScript Coding 7. Jupyter Scala 8. Jupyter and Big Data 9. Interactive Widgets 10. Sharing and Converting Jupyter Notebooks 11. Multiuser Jupyter Notebooks 12. What's Next? 1. Other Books You May Enjoy Index

Scala traits


The trait function in Scala defines a set of features that can be implemented by classes. A trait interface is similar to an interface in Java.

The trait function can be partially implemented, forcing the user (class) of trait to implement the details.

By way of an example, we could have this code:

trait Color {
 def isRed(): Boolean
}
class Red extends Color {
 def isRed() = true
}
class Blue extends Color {
 def isRed() = false
}
var red = new Red();
var blue = new Blue();
red.isRed()
blue.isRed() 

 

The code creates a trait called Color, with one partially implemented function, isRed. So, every class that uses Color will have to implement isRed().

We then implement two classes, Red and Blue, that extend the Color trait (this is the Scala syntax for using trait). Since the isRed() function is partially implemented, both classes have to provide implementations for the trait function.

We can see how this operates in the following Notebook display:

We see (in the output section at the...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime
Visually different images