Skip to content

Instantly share code, notes, and snippets.

@lazyval
Created November 25, 2019 18:44
Show Gist options
  • Save lazyval/03208ebb72e075f2f29a96700f0a0245 to your computer and use it in GitHub Desktop.
Save lazyval/03208ebb72e075f2f29a96700f0a0245 to your computer and use it in GitHub Desktop.
Value classes example
class Meter(val value: Double) extends AnyVal {
def toFeet = new Feet(value * 3.281)
}
class Feet(val value: Double) extends AnyVal {
def toMeter = new Meter(value / 3.281)
}
object Example {
def convert(meter: Meter): Feet = {
meter.toFeet
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment