Created
November 25, 2019 18:44
-
-
Save lazyval/03208ebb72e075f2f29a96700f0a0245 to your computer and use it in GitHub Desktop.
Value classes example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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