Last active
August 29, 2015 14:04
-
-
Save davidandrzej/8ba856345509f6fd8bf3 to your computer and use it in GitHub Desktop.
This file contains 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
def addItUp[F : Monoid](items: Seq[F]): F = { | |
// Combine a bunch of items | |
val m = implicitly[Monoid[F]] | |
items.foldLeft(m.zero){case (total, next) => m.append(total,next)} | |
} | |
scala> addItUp(Seq("day ", "after ", "day")) | |
res1: String = "day after day" | |
scala> addItUp(Seq(1,2,3)) | |
res2: Int = 6 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment