Skip to content

Instantly share code, notes, and snippets.

@teldosas
teldosas / Linear.scala
Last active Jan 14, 2017 — forked from limansky/Linear.scala
Linear type class
View Linear.scala
package me.limansky
import shapeless.ops.hlist.Prepend
import shapeless.{::, <:!<, Generic, HList, HNil, LabelledGeneric, Lazy}
import shapeless.labelled.FieldType
trait UnZip[-F,T] {
def apply(f: F): T
}
@tixxit
tixxit / EditDistance.scala
Created Sep 28, 2011
Short Levenshtein distance implementation in Scala
View EditDistance.scala
package net.tixxit.levenshtein
import scala.math.min
object EditDistance {
def editDist[A](a: Iterable[A], b: Iterable[A]) =
((0 to b.size).toList /: a)((prev, x) =>
(prev zip prev.tail zip b).scanLeft(prev.head + 1) {
case (h, ((d, v), y)) => min(min(h + 1, v + 1), d + (if (x == y) 0 else 1))
}) last