斯卡拉語法所以這個編譯:的lambda函數
def compress[T](list: List[T]): List[(T, Int)] =
{
list.zipWithIndex.filter { tuple => (tuple._2 == 0) || (tuple._1 != list(tuple._2 - 1)) }
}
這並不編譯:
def compress[T](list: List[T]): List[(T, Int)] =
{
list.zipWithIndex.filter { (_._2 == 0) || (_._1 != list(_._2 - 1)) }
}
爲什麼?
我總是使用'case(x,y)'語法,但't2','t3'也是很好的替代品 – 2012-07-23 09:40:06