Skip to content

Instantly share code, notes, and snippets.

View rohinp's full-sized avatar

Rohin rohinp

  • Amsterdam, The Netherlands
View GitHub Profile
//this wont work as type T is unware of the operation +
//value 0 is not a zero value for type T
def summ[T](xs:List[T]):T = xs.foldLeft(0)(_ + _)
//We will take a really simple example of summing a list of ints
def summ(xs:List[Int]):Int = xs.foldLeft(0)(_ + _)
//there is a reason why we have selected foldLeft operation
//May be later in the blog it will be clear.
trait Monoid[T] {
def associative(t1:T,t2:T):
def zero:T
}