Skip to content

Instantly share code, notes, and snippets.

@deanwampler
Last active December 27, 2020 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deanwampler/bf09427538c38041c65ba028e935312f to your computer and use it in GitHub Desktop.
Save deanwampler/bf09427538c38041c65ba028e935312f to your computer and use it in GitHub Desktop.
given NumericMonoid[T](using num: Numeric[T]): Monoid[T] with
def unit: T = num.zero
extension (t: T) def combine(other: T): T = num.plus(t, other)
2.2 <+> (3.3 <+> 4.4) // 9.9
(2.2 <+> 3.3) <+> 4.4 // 9.9
BigDecimal(3.14) <+> NumericMonoid.unit
NumericMonoid[BigDecimal].unit <+> BigDecimal(3.14)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment