Opaque types

Magda Stożek

Get more clarity with

The perfect model

  • Precise
  • Readable
  • Prevents mistakes

Scala 2

  • Type aliases
  • Refined types
  • Value classes
type Age = Int
case class Age(value: Int) extends AnyVal
type Age = Int Refined Positive

Opaque type aliases

Demo:

  • why "opaque"
  • how to add API
    • object methods
    • instance methods
  • bounds

Summary

 

Advantages:

  • simple and clear
  • no overhead
  • opaque

 

Disadvantages:

  • no API (*unless bounds)
  • no pattern matching
  • no toString/equals overriding

Read more

Questions?

  opaque type EndOfPresentation = TimeToAskQuestions
http://bit.ly/magda-scalalove

Opaque types in Scala 3 [20 min]

By Magda Stożek

Opaque types in Scala 3 [20 min]

  • 1,676