summaryrefslogtreecommitdiffhomepage
path: root/scala.html.markdown
diff options
context:
space:
mode:
authorGeoff Liu <cangming.liu@gmail.com>2014-11-11 17:42:28 -0800
committerGeoff Liu <cangming.liu@gmail.com>2014-11-11 17:42:28 -0800
commit1761ec868a2aedc1d7ed6bc3d4879c0662050923 (patch)
tree8a579b87524d0be9f0ed116731a6d90768ced393 /scala.html.markdown
parente784f52d33475b0cba059a0c07ad01b0e63578a9 (diff)
parentad951f2615175b917b7410e667ef91d119468c5a (diff)
Merge
Diffstat (limited to 'scala.html.markdown')
-rw-r--r--scala.html.markdown14
1 files changed, 10 insertions, 4 deletions
diff --git a/scala.html.markdown b/scala.html.markdown
index c8932c86..6112faa6 100644
--- a/scala.html.markdown
+++ b/scala.html.markdown
@@ -204,6 +204,7 @@ def showNumbersInRange(a:Int, b:Int):Unit = {
if (a < b)
showNumbersInRange(a + 1, b)
}
+showNumbersInRange(1,14)
// Conditionals
@@ -218,9 +219,6 @@ if (x == 11) println ("yeah") else println("nay")
println(if (x == 10) "yeah" else "nope")
val text = if (x == 10) "yeah" else "nope"
-var i = 0
-while (i < 10) { println("i " + i); i+=1 }
-
#################################################
## 4. Data Structures
@@ -292,7 +290,8 @@ d._2
And now we will explain what these are.
*/
-class Dog {
+class Dog(br: String) {
+ var breed: String = br
//A method called bark, returning a String
def bark: String = {
// the body of the method
@@ -300,6 +299,11 @@ class Dog {
}
}
+val mydog = new Dog("greyhound")
+println(mydog.breed) // => "greyhound"
+println(mydog.bark) // => "Woof, woof!"
+
+
// Classes can contain nearly any other construct, including other classes,
// functions, methods, objects, case classes, traits etc.
@@ -388,6 +392,7 @@ sSquared.reduce (_+_)
// The filter function takes a predicate (a function from A -> Boolean) and
// selects all elements which satisfy the predicate
List(1, 2, 3) filter (_ > 2) // List(3)
+case class Person(name:String, phoneNumber:String)
List(
Person(name = "Dom", age = 23),
Person(name = "Bob", age = 30)
@@ -396,6 +401,7 @@ List(
// Scala a foreach method defined on certain collections that takes a type
// returning Unit (a void method)
+val aListOfNumbers = List(1, 2, 3, 4, 10, 20, 100)
aListOfNumbers foreach (x => println(x))
aListOfNumbers foreach println