Last active
August 29, 2015 14:09
-
-
Save tarunama/cea4fb270688c54bd1af to your computer and use it in GitHub Desktop.
[Scala]PHPerのScala入門メモ(途中) ref: http://qiita.com/tarunama/items/f30420fa117c84274e1b
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait Access { | |
function howTo() { | |
echo "HowTo"; | |
} | |
} | |
class Company { | |
use Access; | |
} | |
$access = new Company(); | |
$access->howTo(); // HowTo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// switchに似たmatchがある.これはScalaっぽくない書き方。 | |
string match { | |
case "hoge" => println("hoge") | |
case "foo" => println("foo") | |
case "bar" => println("bar") | |
case _ => println("placeholder") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val ary = Array(1, 2, 3) | |
for (num <- ary) | |
yield num * 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait Access { | |
def howTo() { | |
println("HowTo") | |
} | |
} | |
class Company extends Access { | |
override def toString = "hoge" | |
} | |
val company = new Company | |
company.howTo() // HowTo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val integerList = List(1, 2, 3) | |
// リストは変更可能 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val stringArray = Array("hoge", "one", "foo") | |
// 配列は変更可能 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment