Created
June 17, 2017 15:48
-
-
Save pfcoperez/fcc4727f2941c830b3085bf2b55f3008 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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