essential-scala | Source code for Underscore 's Essential Scala | Functional Programming library
kandi X-RAY | essential-scala Summary
kandi X-RAY | essential-scala Summary
Essential Scala is an introduction to Scala for professional developers. Essential Scala covers the core Scala patterns that new developers need to be productive in the language. It's designed to get you productive as quickly as possible, and avoid the dark and confusing corners of the language.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of essential-scala
essential-scala Key Features
essential-scala Examples and Code Snippets
Community Discussions
Trending Discussions on essential-scala
QUESTION
Working through the Essential Scala book, I find myself playing with the linked list example. I have wound up with a situation where I have a superclass, for lists of anything, and a subclass for lists of Int
s. I can ask for the length of either type of list, and the sum of a list of ints. However, I am having some trouble modelling this using case classes. The natural inheritance structure is as follows:
ANSWER
Answered 2020-Nov-02 at 08:15You can define your own extractor instead of using case classes. That's how you can use both match and inheritance.
To define an extractor you mast specify unapply method in your object, like that;
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install essential-scala
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page