the-algorithm/follow-recommendations-service/common/src/main/scala/com/twitter/follow_recommendations/common/utils/Weighted.scala
twitter-team ef4c5eb65e Twitter Recommendation Algorithm
Please note we have force-pushed a new initial commit in order to remove some publicly-available Twitter user information. Note that this process may be required in the future.
2023-03-31 17:36:31 -05:00

22 lines
477 B
Scala

package com.twitter.follow_recommendations.common.utils
/**
* Typeclass for any Recommendation type that has a weight
*
*/
trait Weighted[-Rec] {
def apply(rec: Rec): Double
}
object Weighted {
implicit object WeightedTuple extends Weighted[(_, Double)] {
override def apply(rec: (_, Double)): Double = rec._2
}
def fromFunction[Rec](f: Rec => Double): Weighted[Rec] = {
new Weighted[Rec] {
override def apply(rec: Rec): Double = f(rec)
}
}
}