Skip to content

Instantly share code, notes, and snippets.

@tarunama
Last active August 29, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tarunama/cea4fb270688c54bd1af to your computer and use it in GitHub Desktop.
Save tarunama/cea4fb270688c54bd1af to your computer and use it in GitHub Desktop.
[Scala]PHPerのScala入門メモ(途中) ref: http://qiita.com/tarunama/items/f30420fa117c84274e1b
trait Access {
function howTo() {
echo "HowTo";
}
}
class Company {
use Access;
}
$access = new Company();
$access->howTo(); // HowTo
// switchに似たmatchがある.これはScalaっぽくない書き方。
string match {
case "hoge" => println("hoge")
case "foo" => println("foo")
case "bar" => println("bar")
case _ => println("placeholder")
}
val ary = Array(1, 2, 3)
for (num <- ary)
yield num * 2
trait Access {
def howTo() {
println("HowTo")
}
}
class Company extends Access {
override def toString = "hoge"
}
val company = new Company
company.howTo() // HowTo
val integerList = List(1, 2, 3)
// リストは変更可能
val stringArray = Array("hoge", "one", "foo")
// 配列は変更可能
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment