2012-08-24 354 views

回答

5

這正是map是:

def convert(x: Option[Int]) = x map (_.toLong) 

其工作原理是這樣的:

scala> convert(Some(1)) 
res0: Option[Long] = Some(1) 

scala> convert(None) 
res1: Option[Long] = None 

scala.Predef提供從IntRichInt的隱式轉換,這是其中toLong方法得來的。