Skip to content

Instantly share code, notes, and snippets.

val result: Stream[Task, Prediction] = specimenStream.flatMap((spec: Document) =>{
modelStream.fold(List.empty[TopN]) { case (topNVec, mod) =>
val res = calcDistance(spec, mod)
val newTopN = TopN(res.modelElm.label.get, res.distance)
(topNVec :+ newTopN).sortBy(res => res.confidence).take(nearest)
}.map(topNVec => Prediction(spec.text, topNVec.toList) )
})