mirror of
https://github.com/twitter/the-algorithm.git
synced 2024-06-13 06:38:52 +02:00
![twitter-team](/assets/img/avatar_default.png)
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.
22 lines
477 B
Scala
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)
|
|
}
|
|
}
|
|
}
|