Skip to content

Instantly share code, notes, and snippets.

@mfirry
Created October 19, 2016 09:59
Show Gist options
  • Save mfirry/ba215193dd7e3494b643e9b3f4d6a9d8 to your computer and use it in GitHub Desktop.
Save mfirry/ba215193dd7e3494b643e9b3f4d6a9d8 to your computer and use it in GitHub Desktop.
cats-like implementation of CommutativeGroup for BigDecimal
class BigDecimalGroup extends CommutativeGroup[BigDecimal] {
def combine(x: BigDecimal, y: BigDecimal): BigDecimal = x + y
def empty: BigDecimal = 0
def inverse(x: BigDecimal): BigDecimal = -x
override def remove(x: BigDecimal, y: BigDecimal): BigDecimal = x - y
}
implicit val catsKernelStdGroupForBigDecimal: CommutativeGroup[BigDecimal] = new BigDecimalGroup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment