SlideShare a Scribd company logo
SHAPELESSSHAPELESS
Generic programming for
Scala !
Generic programming for
Scala !
Deepti Bhardwaj
Trainee Software Consultant
Knoldus Software LLP
What is Shapeless?
โ— Type class
โ— Dependent type based generic programming
library for Scala
โ— Type class
โ— Dependent type based generic programming
library for Scala
Why Shapeless ?
โ— Shapeless is about programming with types.
โ— Doing things at compile-time that would more
commonly be done at runtime to ensure type-
safety and effectiveness.
Using Shapeless:
To include it in your SBT build you should add:
scalaVersion := "2.11.7"
libraryDependencies ++= Seq(
"com.chuusai" %% "shapeless" % "2.3.0")
1)Polymorphic function values
โ— Ordinary Scala function values are
monomorphic. Shapeless, however, provides
an encoding of polymorphic function values.
// Monomorphic method example
def findSize(s: String): Int = s.length
monomorphic("foo")
// Polymorphic method example
def findSize[T](l: List[T]): Int = l.length
findSize(List(1, 2, 3))
findSize(List("foo", "bar", "baz"))
Defining polymorphic function
values:
โ— The parametric polymorphism is moved to the method
inside the object.
โ— They are able to capture type-specific cases.
โ— Being polymorphic, they may be passed as arguments to
functions or methods and then applied to values of
different types within those functions.
HList Vs List
HLists are lists of objects of arbitrary types,
where the type information for each object is
kept. In fact, in Scala, we may do:
import shapeless._
val l = 10 :: "string" :: 1.0 :: Nil
but the type of l then would be List[Any], because
the common super type of the elements there
would be, in fact, only Any. A HList is declared
similarly to a List:
val hl = 10 :: "string" :: 1.0 :: HNil
except for the terminator HNil. But the type of hl is
actually Int :: String :: Double :: HNil.
HList vs Tuple
The benefit of using HLists instead of tuples is
that they can be used in all those situations
where a tuple would work just as well, but
without the 22-elements limit.
Also, shapeless allows standard Scala tuples
to be manipulated in exactly the same ways as
HLists.
2)Heterogenous lists
โ— It has a map operation, applying a
polymorphic function value across its
elements.
โ— It also has a flatMap operation.
โ— It has a set of fully polymorphic fold operations
which take a polymorphic binary function
value. The fold is sensitive to the static types
of all of the elements of the Hlist
3)Heterogenous maps
Shapeless provides a heterogenous map which
supports an arbitrary relation between the key
type and the corresponding value type,
class BiMapIS[K, V]
implicit val intToString = new BiMapIS[Int,String]
implicit val stringToInt = new BiMapIS[String, Int]
//this implies the map thus declared can have int as key and
String as value and vice - versa
monomorphic Scala map => monomorphic
function value
heterogenous shapeless map => polymorphic
function value
4)Coproduct
โ— a generalization of Scala's Either to an arbitrary number
of choices
โ— allows you to put together more than two types.
โ— Either with more than two possible types.
โ— Coproducts are mutually exclusive, only one of the
elements is going to be present at runtime.
5)Generic
โ— Simply put, a case class can be represented generically
as an HList of its component types โ€” known as the
โ€œgeneric representationโ€
โ— Converting a case class to/from its generic
representation is accomplished by using Generic!
trait Generic[T] {
type Repr
def to(t:T) :Repr
def from(r:Repr) :T }
case class Intern(name: String, email: String,id
:Int, address:String)
case class Employee(name: String, email:
String,id :Int, address:String)
we want to construct Employee from Intern
but want to do it automatically without passing
all parameters. Generic is used here !!
In this case, Employee and Intern are nearly
identical. What if the Employee had an extra
property or a less property?
The solution is provided by LabelledGeneric!
In this case, Employee and Intern are nearly
identical. What if the Employee had an extra
property or a less property?
The solution is provided by LabelledGeneric!
6)LabelledGeneric
โ— a case class can be represented generically
as a record of its component fields โ€” known
as the โ€œlabelled generic representationโ€
References
https://github.com/milessabin/shapeless/wiki/Feature-https://github.com/milessabin/shapeless/wiki/Feature-
Demo
https://github.com/knoldus/shapeless-demo
Shapeless- Generic programming for Scala
Shapeless- Generic programming for Scala

More Related Content

What's hot (20)

PPTX
TypeScript
Oswald Campesato
ย 
PDF
Why Java Sucks and C# Rocks (Final)
jeffz
ย 
PPTX
Introduction to JavaScript
Rangana Sampath
ย 
ODP
String interpolation
Knoldus Inc.
ย 
PDF
SE 20016 - programming languages landscape.
Ruslan Shevchenko
ย 
PPT
Introduction To C#
SAMIR BHOGAYTA
ย 
PPTX
All You Need to Know About Type Script
Folio3 Software
ย 
ODP
Pattern Matching - at a glance
Knoldus Inc.
ย 
PDF
1 kotlin vs. java: some java issues addressed in kotlin
Sergey Bandysik
ย 
PDF
Few simple-type-tricks in scala
Ruslan Shevchenko
ย 
PPT
Introduction to c#
OpenSource Technologies Pvt. Ltd.
ย 
PPT
An introduction to javascript
MD Sayem Ahmed
ย 
PPTX
Scala Intro
Alexey (Mr_Mig) Migutsky
ย 
PPT
JavaScript Data Types
Charles Russell
ย 
PPT
The JavaScript Programming Language
Raghavan Mohan
ย 
PPTX
Java Tutorial Lab 5
Berk Soysal
ย 
ODP
String Interpolation in Scala
Knoldus Inc.
ย 
PPT
Static and dynamic polymorphism
umesh patil
ย 
PPTX
Javascript analysis
Uchitha Bandara
ย 
TypeScript
Oswald Campesato
ย 
Why Java Sucks and C# Rocks (Final)
jeffz
ย 
Introduction to JavaScript
Rangana Sampath
ย 
String interpolation
Knoldus Inc.
ย 
SE 20016 - programming languages landscape.
Ruslan Shevchenko
ย 
Introduction To C#
SAMIR BHOGAYTA
ย 
All You Need to Know About Type Script
Folio3 Software
ย 
Pattern Matching - at a glance
Knoldus Inc.
ย 
1 kotlin vs. java: some java issues addressed in kotlin
Sergey Bandysik
ย 
Few simple-type-tricks in scala
Ruslan Shevchenko
ย 
Introduction to c#
OpenSource Technologies Pvt. Ltd.
ย 
An introduction to javascript
MD Sayem Ahmed
ย 
Scala Intro
Alexey (Mr_Mig) Migutsky
ย 
JavaScript Data Types
Charles Russell
ย 
The JavaScript Programming Language
Raghavan Mohan
ย 
Java Tutorial Lab 5
Berk Soysal
ย 
String Interpolation in Scala
Knoldus Inc.
ย 
Static and dynamic polymorphism
umesh patil
ย 
Javascript analysis
Uchitha Bandara
ย 

Viewers also liked (20)

ODP
BDD with Cucumber
Knoldus Inc.
ย 
ODP
Walk-through: Amazon ECS
Knoldus Inc.
ย 
PDF
ใ“ใ‚ŒใŒใ‚ใ‹ใ‚‹ใจshapelessใฎใ‚ณใƒผใƒ‰ใ‚‚่ชญใ‚ใ‚‹ใ‹ใ‚‚ใ—ใ‚Œใชใ„
Yasuki Okumura
ย 
ODP
Introduction to Scala JS
Knoldus Inc.
ย 
ODP
Drilling the Async Library
Knoldus Inc.
ย 
ODP
Akka streams
Knoldus Inc.
ย 
ODP
Getting Started With AureliaJs
Knoldus Inc.
ย 
ODP
Mailchimp and Mandrill - The โ€˜Hominidaeโ€™ kingdom
Knoldus Inc.
ย 
ODP
Realm Mobile Database - An Introduction
Knoldus Inc.
ย 
PDF
Kanban
Knoldus Inc.
ย 
ODP
Introduction to Scala Macros
Knoldus Inc.
ย 
ODP
Introduction to Java 8
Knoldus Inc.
ย 
ODP
An Introduction to Quill
Knoldus Inc.
ย 
ODP
Mandrill Templates
Knoldus Inc.
ย 
ODP
Introduction to Knockout Js
Knoldus Inc.
ย 
ODP
Effective way to code in Scala
Knoldus Inc.
ย 
ODP
Introduction to ScalaZ
Knoldus Inc.
ย 
ODP
ANTLR4 and its testing
Knoldus Inc.
ย 
ODP
HTML5, CSS, JavaScript Style guide and coding conventions
Knoldus Inc.
ย 
ODP
Functional programming in Javascript
Knoldus Inc.
ย 
BDD with Cucumber
Knoldus Inc.
ย 
Walk-through: Amazon ECS
Knoldus Inc.
ย 
ใ“ใ‚ŒใŒใ‚ใ‹ใ‚‹ใจshapelessใฎใ‚ณใƒผใƒ‰ใ‚‚่ชญใ‚ใ‚‹ใ‹ใ‚‚ใ—ใ‚Œใชใ„
Yasuki Okumura
ย 
Introduction to Scala JS
Knoldus Inc.
ย 
Drilling the Async Library
Knoldus Inc.
ย 
Akka streams
Knoldus Inc.
ย 
Getting Started With AureliaJs
Knoldus Inc.
ย 
Mailchimp and Mandrill - The โ€˜Hominidaeโ€™ kingdom
Knoldus Inc.
ย 
Realm Mobile Database - An Introduction
Knoldus Inc.
ย 
Kanban
Knoldus Inc.
ย 
Introduction to Scala Macros
Knoldus Inc.
ย 
Introduction to Java 8
Knoldus Inc.
ย 
An Introduction to Quill
Knoldus Inc.
ย 
Mandrill Templates
Knoldus Inc.
ย 
Introduction to Knockout Js
Knoldus Inc.
ย 
Effective way to code in Scala
Knoldus Inc.
ย 
Introduction to ScalaZ
Knoldus Inc.
ย 
ANTLR4 and its testing
Knoldus Inc.
ย 
HTML5, CSS, JavaScript Style guide and coding conventions
Knoldus Inc.
ย 
Functional programming in Javascript
Knoldus Inc.
ย 
Ad

Similar to Shapeless- Generic programming for Scala (20)

PDF
Automatic Type Class Derivation with Shapeless
jcazevedo
ย 
PDF
Algebraic Data Types and Origami Patterns
Vasil Remeniuk
ย 
PDF
Programming in Scala - Lecture Three
Angelo Corsaro
ย 
PDF
Scala for Java Devs
loverdos
ย 
PDF
Scala Paradigms
Tom Flaherty
ย 
PDF
Introduction to Scala for Java Developers
Michael Galpin
ย 
PDF
Why functional programming and category theory strongly matters - Piotr Parad...
Scalac
ย 
PDF
Why functional programming and category theory strongly matters
Piotr Paradziล„ski
ย 
PDF
Scala jargon cheatsheet
Ruslan Shevchenko
ย 
PDF
A Brief Introduction to Scala for Java Developers
Miles Sabin
ย 
PDF
Miles Sabin Introduction To Scala For Java Developers
Skills Matter
ย 
PDF
Sequence and Traverse - Part 3
Philip Schwarz
ย 
PDF
Bartosz kowalik Shapeless Matrix
PROIDEA
ย 
PDF
Flavour of meta-programming with shapeless
Arthur Kushka
ย 
PPTX
Scala 3 Is Coming: Martin Odersky Shares What To Know
Lightbend
ย 
PDF
Introduction ร  Scala - Michel Schinz - January 2010
JUG Lausanne
ย 
PPTX
Scala Refactoring for Fun and Profit
Tomer Gabel
ย 
PDF
Stepping Up : A Brief Intro to Scala
Derek Chen-Becker
ย 
PDF
BCS SPA 2010 - An Introduction to Scala for Java Developers
Miles Sabin
ย 
PDF
An Introduction to Scala for Java Developers
Miles Sabin
ย 
Automatic Type Class Derivation with Shapeless
jcazevedo
ย 
Algebraic Data Types and Origami Patterns
Vasil Remeniuk
ย 
Programming in Scala - Lecture Three
Angelo Corsaro
ย 
Scala for Java Devs
loverdos
ย 
Scala Paradigms
Tom Flaherty
ย 
Introduction to Scala for Java Developers
Michael Galpin
ย 
Why functional programming and category theory strongly matters - Piotr Parad...
Scalac
ย 
Why functional programming and category theory strongly matters
Piotr Paradziล„ski
ย 
Scala jargon cheatsheet
Ruslan Shevchenko
ย 
A Brief Introduction to Scala for Java Developers
Miles Sabin
ย 
Miles Sabin Introduction To Scala For Java Developers
Skills Matter
ย 
Sequence and Traverse - Part 3
Philip Schwarz
ย 
Bartosz kowalik Shapeless Matrix
PROIDEA
ย 
Flavour of meta-programming with shapeless
Arthur Kushka
ย 
Scala 3 Is Coming: Martin Odersky Shares What To Know
Lightbend
ย 
Introduction ร  Scala - Michel Schinz - January 2010
JUG Lausanne
ย 
Scala Refactoring for Fun and Profit
Tomer Gabel
ย 
Stepping Up : A Brief Intro to Scala
Derek Chen-Becker
ย 
BCS SPA 2010 - An Introduction to Scala for Java Developers
Miles Sabin
ย 
An Introduction to Scala for Java Developers
Miles Sabin
ย 
Ad

More from Knoldus Inc. (20)

PPTX
Angular Hydration Presentation (FrontEnd)
Knoldus Inc.
ย 
PPTX
Optimizing Test Execution: Heuristic Algorithm for Self-Healing
Knoldus Inc.
ย 
PPTX
Self-Healing Test Automation Framework - Healenium
Knoldus Inc.
ย 
PPTX
Kanban Metrics Presentation (Project Management)
Knoldus Inc.
ย 
PPTX
Java 17 features and implementation.pptx
Knoldus Inc.
ย 
PPTX
Chaos Mesh Introducing Chaos in Kubernetes
Knoldus Inc.
ย 
PPTX
GraalVM - A Step Ahead of JVM Presentation
Knoldus Inc.
ย 
PPTX
Nomad by HashiCorp Presentation (DevOps)
Knoldus Inc.
ย 
PPTX
Nomad by HashiCorp Presentation (DevOps)
Knoldus Inc.
ย 
PPTX
DAPR - Distributed Application Runtime Presentation
Knoldus Inc.
ย 
PPTX
Introduction to Azure Virtual WAN Presentation
Knoldus Inc.
ย 
PPTX
Introduction to Argo Rollouts Presentation
Knoldus Inc.
ย 
PPTX
Intro to Azure Container App Presentation
Knoldus Inc.
ย 
PPTX
Insights Unveiled Test Reporting and Observability Excellence
Knoldus Inc.
ย 
PPTX
Introduction to Splunk Presentation (DevOps)
Knoldus Inc.
ย 
PPTX
Code Camp - Data Profiling and Quality Analysis Framework
Knoldus Inc.
ย 
PPTX
AWS: Messaging Services in AWS Presentation
Knoldus Inc.
ย 
PPTX
Amazon Cognito: A Primer on Authentication and Authorization
Knoldus Inc.
ย 
PPTX
ZIO Http A Functional Approach to Scalable and Type-Safe Web Development
Knoldus Inc.
ย 
PPTX
Managing State & HTTP Requests In Ionic.
Knoldus Inc.
ย 
Angular Hydration Presentation (FrontEnd)
Knoldus Inc.
ย 
Optimizing Test Execution: Heuristic Algorithm for Self-Healing
Knoldus Inc.
ย 
Self-Healing Test Automation Framework - Healenium
Knoldus Inc.
ย 
Kanban Metrics Presentation (Project Management)
Knoldus Inc.
ย 
Java 17 features and implementation.pptx
Knoldus Inc.
ย 
Chaos Mesh Introducing Chaos in Kubernetes
Knoldus Inc.
ย 
GraalVM - A Step Ahead of JVM Presentation
Knoldus Inc.
ย 
Nomad by HashiCorp Presentation (DevOps)
Knoldus Inc.
ย 
Nomad by HashiCorp Presentation (DevOps)
Knoldus Inc.
ย 
DAPR - Distributed Application Runtime Presentation
Knoldus Inc.
ย 
Introduction to Azure Virtual WAN Presentation
Knoldus Inc.
ย 
Introduction to Argo Rollouts Presentation
Knoldus Inc.
ย 
Intro to Azure Container App Presentation
Knoldus Inc.
ย 
Insights Unveiled Test Reporting and Observability Excellence
Knoldus Inc.
ย 
Introduction to Splunk Presentation (DevOps)
Knoldus Inc.
ย 
Code Camp - Data Profiling and Quality Analysis Framework
Knoldus Inc.
ย 
AWS: Messaging Services in AWS Presentation
Knoldus Inc.
ย 
Amazon Cognito: A Primer on Authentication and Authorization
Knoldus Inc.
ย 
ZIO Http A Functional Approach to Scalable and Type-Safe Web Development
Knoldus Inc.
ย 
Managing State & HTTP Requests In Ionic.
Knoldus Inc.
ย 

Recently uploaded (20)

PPTX
IDM Crack with Internet Download Manager 6.42 [Latest 2025]
HyperPc soft
ย 
PPTX
IObit Driver Booster Pro 12.4-12.5 license keys 2025-2026
chaudhryakashoo065
ย 
PPTX
IObit Driver Booster Pro Crack Download Latest Version
chaudhryakashoo065
ย 
PDF
Building scalbale cloud native apps with .NET 8
GillesMathieu10
ย 
PDF
Rewards and Recognition (2).pdf
ethan Talor
ย 
PDF
IDM Crack with Internet Download Manager 6.42 Build 41
utfefguu
ย 
PPTX
Seamless-Image-Conversion-From-Raster-to-wrt-rtx-rtx.pptx
Quick Conversion Services
ย 
PDF
Cloud computing Lec 02 - virtualization.pdf
asokawennawatte
ย 
PDF
AWS Consulting Services: Empowering Digital Transformation with Nlineaxis
Nlineaxis IT Solutions Pvt Ltd
ย 
PDF
The Rise of Sustainable Mobile App Solutions by New York Development Firms
ostechnologies16
ย 
PDF
AI Software Development Process, Strategies and Challenges
Net-Craft.com
ย 
PDF
Power BI vs Tableau vs Looker - Which BI Tool is Right for You?
MagnusMinds IT Solution LLP
ย 
PDF
capitulando la keynote de GrafanaCON 2025 - Madrid
Imma Valls Bernaus
ย 
PDF
Difference Between Kubernetes and Docker .pdf
Kindlebit Solutions
ย 
PDF
Alur Perkembangan Software dan Jaringan Komputer
ssuser754303
ย 
PPTX
Iobit Driver Booster Pro 12 Crack Free Download
chaudhryakashoo065
ย 
PDF
Continouous failure - Why do we make our lives hard?
Papp Krisztiรกn
ย 
PDF
LPS25 - Operationalizing MLOps in GEP - Terradue.pdf
terradue
ย 
PPTX
EO4EU Ocean Monitoring: Maritime Weather Routing Optimsation Use Case
EO4EU
ย 
PDF
>Nitro Pro Crack 14.36.1.0 + Keygen Free Download [Latest]
utfefguu
ย 
IDM Crack with Internet Download Manager 6.42 [Latest 2025]
HyperPc soft
ย 
IObit Driver Booster Pro 12.4-12.5 license keys 2025-2026
chaudhryakashoo065
ย 
IObit Driver Booster Pro Crack Download Latest Version
chaudhryakashoo065
ย 
Building scalbale cloud native apps with .NET 8
GillesMathieu10
ย 
Rewards and Recognition (2).pdf
ethan Talor
ย 
IDM Crack with Internet Download Manager 6.42 Build 41
utfefguu
ย 
Seamless-Image-Conversion-From-Raster-to-wrt-rtx-rtx.pptx
Quick Conversion Services
ย 
Cloud computing Lec 02 - virtualization.pdf
asokawennawatte
ย 
AWS Consulting Services: Empowering Digital Transformation with Nlineaxis
Nlineaxis IT Solutions Pvt Ltd
ย 
The Rise of Sustainable Mobile App Solutions by New York Development Firms
ostechnologies16
ย 
AI Software Development Process, Strategies and Challenges
Net-Craft.com
ย 
Power BI vs Tableau vs Looker - Which BI Tool is Right for You?
MagnusMinds IT Solution LLP
ย 
capitulando la keynote de GrafanaCON 2025 - Madrid
Imma Valls Bernaus
ย 
Difference Between Kubernetes and Docker .pdf
Kindlebit Solutions
ย 
Alur Perkembangan Software dan Jaringan Komputer
ssuser754303
ย 
Iobit Driver Booster Pro 12 Crack Free Download
chaudhryakashoo065
ย 
Continouous failure - Why do we make our lives hard?
Papp Krisztiรกn
ย 
LPS25 - Operationalizing MLOps in GEP - Terradue.pdf
terradue
ย 
EO4EU Ocean Monitoring: Maritime Weather Routing Optimsation Use Case
EO4EU
ย 
>Nitro Pro Crack 14.36.1.0 + Keygen Free Download [Latest]
utfefguu
ย 

Shapeless- Generic programming for Scala

  • 1. SHAPELESSSHAPELESS Generic programming for Scala ! Generic programming for Scala ! Deepti Bhardwaj Trainee Software Consultant Knoldus Software LLP
  • 2. What is Shapeless? โ— Type class โ— Dependent type based generic programming library for Scala โ— Type class โ— Dependent type based generic programming library for Scala
  • 3. Why Shapeless ? โ— Shapeless is about programming with types. โ— Doing things at compile-time that would more commonly be done at runtime to ensure type- safety and effectiveness.
  • 4. Using Shapeless: To include it in your SBT build you should add: scalaVersion := "2.11.7" libraryDependencies ++= Seq( "com.chuusai" %% "shapeless" % "2.3.0")
  • 5. 1)Polymorphic function values โ— Ordinary Scala function values are monomorphic. Shapeless, however, provides an encoding of polymorphic function values.
  • 6. // Monomorphic method example def findSize(s: String): Int = s.length monomorphic("foo") // Polymorphic method example def findSize[T](l: List[T]): Int = l.length findSize(List(1, 2, 3)) findSize(List("foo", "bar", "baz"))
  • 7. Defining polymorphic function values: โ— The parametric polymorphism is moved to the method inside the object. โ— They are able to capture type-specific cases. โ— Being polymorphic, they may be passed as arguments to functions or methods and then applied to values of different types within those functions.
  • 8. HList Vs List HLists are lists of objects of arbitrary types, where the type information for each object is kept. In fact, in Scala, we may do: import shapeless._ val l = 10 :: "string" :: 1.0 :: Nil
  • 9. but the type of l then would be List[Any], because the common super type of the elements there would be, in fact, only Any. A HList is declared similarly to a List: val hl = 10 :: "string" :: 1.0 :: HNil except for the terminator HNil. But the type of hl is actually Int :: String :: Double :: HNil.
  • 10. HList vs Tuple The benefit of using HLists instead of tuples is that they can be used in all those situations where a tuple would work just as well, but without the 22-elements limit. Also, shapeless allows standard Scala tuples to be manipulated in exactly the same ways as HLists.
  • 11. 2)Heterogenous lists โ— It has a map operation, applying a polymorphic function value across its elements. โ— It also has a flatMap operation.
  • 12. โ— It has a set of fully polymorphic fold operations which take a polymorphic binary function value. The fold is sensitive to the static types of all of the elements of the Hlist
  • 13. 3)Heterogenous maps Shapeless provides a heterogenous map which supports an arbitrary relation between the key type and the corresponding value type, class BiMapIS[K, V] implicit val intToString = new BiMapIS[Int,String] implicit val stringToInt = new BiMapIS[String, Int] //this implies the map thus declared can have int as key and String as value and vice - versa
  • 14. monomorphic Scala map => monomorphic function value heterogenous shapeless map => polymorphic function value
  • 15. 4)Coproduct โ— a generalization of Scala's Either to an arbitrary number of choices โ— allows you to put together more than two types. โ— Either with more than two possible types. โ— Coproducts are mutually exclusive, only one of the elements is going to be present at runtime.
  • 16. 5)Generic โ— Simply put, a case class can be represented generically as an HList of its component types โ€” known as the โ€œgeneric representationโ€ โ— Converting a case class to/from its generic representation is accomplished by using Generic! trait Generic[T] { type Repr def to(t:T) :Repr def from(r:Repr) :T }
  • 17. case class Intern(name: String, email: String,id :Int, address:String) case class Employee(name: String, email: String,id :Int, address:String) we want to construct Employee from Intern but want to do it automatically without passing all parameters. Generic is used here !!
  • 18. In this case, Employee and Intern are nearly identical. What if the Employee had an extra property or a less property? The solution is provided by LabelledGeneric! In this case, Employee and Intern are nearly identical. What if the Employee had an extra property or a less property? The solution is provided by LabelledGeneric!
  • 19. 6)LabelledGeneric โ— a case class can be represented generically as a record of its component fields โ€” known as the โ€œlabelled generic representationโ€