Skip to content

Instantly share code, notes, and snippets.

@rhwlo
Last active November 8, 2015 18:37
Show Gist options
  • Save rhwlo/9508955802565f27c973 to your computer and use it in GitHub Desktop.
Save rhwlo/9508955802565f27c973 to your computer and use it in GitHub Desktop.
// a Modifier implements a modifier function
sealed abstract class Modifier {
def modify(measure: Measure): Measure
}
case class Prefix(prefix: String, modify(measure: Measure): Measure) extends Modifier
class Exponent(power: Int) extends Modifier {
def modify(measure: Measure): Measure = {
Range(1, power).foldLeft(measure)(case (m, _) => m.multiply(measure))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment