Skip to content

Instantly share code, notes, and snippets.

@nuttycom
Created March 19, 2010 15:46
Show Gist options
  • Save nuttycom/337650 to your computer and use it in GitHub Desktop.
Save nuttycom/337650 to your computer and use it in GitHub Desktop.
import java.util.UUID
object Test {
implicit def columnMap2Map[A, B](map: Map[Array[Byte], Array[Byte]]) = new MapConverter(map)
class MapConverter(map: Map[Array[Byte], Array[Byte]]) {
def to[A, B](implicit f: Array[Byte] => A, g: Array[Byte] => B): Map[A, B] = {
map.foldLeft(Map[A, B]()) { case(map, (k, v)) =>
val tuple = (k: A, v: B)
map + tuple
}
}
}
implicit def byteArray2UUID(bytes: Array[Byte]): UUID = UUID.fromString(new String(bytes))
implicit def byteArray2Str(bytes: Array[Byte]): String = new String(bytes)
implicit def string2ByteArray(string: String): Array[Byte] = string.getBytes
def main(argv: Array[String]) {
val test = Map[Array[Byte], Array[Byte]]()
val result = test.to[UUID, String]
print(result)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment