Skip to content

Commit

Permalink
Merge pull request #80 from asiegel34/specialize-max
Browse files Browse the repository at this point in the history
specialize Max,Min,First,Last on the usual primitives
  • Loading branch information
johnynek committed Dec 18, 2012
2 parents d614b5a + 6f6fcd4 commit 5ebf209
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/main/scala/com/twitter/algebird/OrderedSemigroup.scala
Expand Up @@ -16,15 +16,15 @@ limitations under the License.
package com.twitter.algebird

// To use the MaxSemigroup wrap your item in a Max object
case class Max[+T](get: T)
case class Max[@specialized(Int,Long,Float,Double) +T](get: T)

object Max {
implicit def semigroup[T](implicit ord:Ordering[T]) =
Semigroup.from[Max[T]] { (l,r) => if(ord.gteq(l.get, r.get)) l else r }
}

// To use the MinSemigroup wrap your item in a Min object
case class Min[+T](get: T)
case class Min[@specialized(Int,Long,Float,Double) +T](get: T)

object Min {
implicit def semigroup[T](implicit ord:Ordering[T]) =
Expand All @@ -33,12 +33,12 @@ object Min {

// Not ordered by type, but ordered by order in which we see them:

case class First[+T](get: T)
case class First[@specialized(Int,Long,Float,Double) +T](get: T)
object First {
implicit def semigroup[T] = Semigroup.from[First[T]] { (l,r) => l }
}

case class Last[+T](get: T)
case class Last[@specialized(Int,Long,Float,Double) +T](get: T)
object Last {
implicit def semigroup[T] = Semigroup.from[Last[T]] { (l,r) => r }
}

0 comments on commit 5ebf209

Please sign in to comment.