Created
March 19, 2010 15:46
-
-
Save nuttycom/337650 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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