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 18:06:19 -0800
commit9d8d8710053a73e5099483f9e07c9d789cec73e5 (patch)
tree7da03b2bef2c7fa5e9a8ea0ddc4acf919bce980f /scala.html.markdown
parente784f52d33475b0cba059a0c07ad01b0e63578a9 (diff)
parentad951f2615175b917b7410e667ef91d119468c5a (diff)
Merge
Diffstat (limited to 'scala.html.markdown')
-rw-r--r--scala.html.markdown16
1 files changed, 11 insertions, 5 deletions
diff --git a/scala.html.markdown b/scala.html.markdown
index c8932c86..6964b9a0 100644
--- a/scala.html.markdown
+++ b/scala.html.markdown
@@ -100,7 +100,7 @@ true == false // false
"Scala strings are surrounded by double quotes"
'a' // A Scala Char
-'Single quote strings don't exist' // Error
+// 'Single quote strings don't exist' <= This causes an error
// Strings have the usual Java methods defined on them
"hello world".length
@@ -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