Selasa, 11 Januari 2011

yield

$ scala
cygwin warning:
MS-DOS style path detected: d:\jdk1.6/bin/java
Preferred POSIX equivalent is: /cygdrive/d/jdk1.6/bin/java
CYGWIN environment variable option "nodosfilewarning" turns off this warning.
Consult the user's guide for more details about POSIX paths:
http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
Welcome to Scala version 2.7.7.final (Java HotSpot(TM) Client VM, Java 1.6.0_13).
Type in expressions to have them evaluated.
Type :help for more information.

scala> var aList = List(1,2,3,4,5)
aList: List[Int] = List(1, 2, 3, 4, 5)

scala> for(num <- aList) yield num * 10 res0: List[Int] = List(10, 20, 30, 40, 50) scala> aList.map( i => i * 10 )
res1: List[Int] = List(10, 20, 30, 40, 50)


$ scala
Welcome to Scala version 2.7.7.final (Java HotSpot(TM) Client VM, Java 1.6.0_13).
Type in expressions to have them evaluated.
Type :help for more information.

scala> var aList = List(1,2,3,4,5)
aList: List[Int] = List(1, 2, 3, 4, 5)

scala> for(num <- aList) yield println(num * 10)
10
20
30
40
50
res0: List[Unit] = List((), (), (), (), ())

Tidak ada komentar:

Posting Komentar