Skip to content

Instantly share code, notes, and snippets.

@pfcoperez
Created June 17, 2017 15:48
Show Gist options
  • Save pfcoperez/fcc4727f2941c830b3085bf2b55f3008 to your computer and use it in GitHub Desktop.
Save pfcoperez/fcc4727f2941c830b3085bf2b55f3008 to your computer and use it in GitHub Desktop.
import cats.Monoid
import cats.syntax.monoid._
case class Order(products: List[String], topay: Double)
//This could be done with higher abstraction cats tools
implicit val orderMonoidInstance: Monoid[Order] = new Monoid[Order] {
def empty: Order = Order(Nil, 0.0)
def combine(x: Order, y: Order): Order = Order(x.products ++ y.products, x.topay + y.topay)
}
val orders = Order("fp2016"::Nil, 20.0)::Order("bananas"::"apples"::Nil, 10.0)::Nil
orders.combineAll
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment