Skip to content

Instantly share code, notes, and snippets.

@Centaur
Last active August 29, 2015 13:59
Show Gist options
  • Save Centaur/10712712 to your computer and use it in GitHub Desktop.
Save Centaur/10712712 to your computer and use it in GitHub Desktop.
def pair(s: String, key: Int, value: Int): (String,String) = {
val arr = s.split(",")
arr(key) -> arr(value)
}
def pair[V](s: String, key: Int, value: (Int, String => V)): (String,V) = {
val arr = s.split(",")
arr(key) -> value._2.apply(arr(value._1))
}
def pair[K](s: String, key: (Int, String => K), value: Int): (K, String) = {
val arr = s.split(",")
key._2.apply(arr(key._1)) -> arr(value)
}
def pair[K, V](s: String, key: (Int, String => K), value: (Int, String => V)): (K, V) = {
val arr = s.split(",")
key._2.apply(arr(key._1)) -> value._2.apply(arr(value._1))
}
assert(pair("0001,notyy,37", 0, 1) == ("0001", "notyy"))
assert(pair("0001,notyy,37", 0 -> ((_:String).toInt), 1) == (1, "notyy"))
assert(pair("0001,notyy,37", 0, 1 -> Symbol.apply _) == ("0001", 'notyy))
assert(pair("0001,notyy,37", 0 -> ((_:String).toInt), 1 -> Symbol.apply _) == (1, 'notyy))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment