This file contains hidden or 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
| object OmitParenthesis { | |
| def test = "test" | |
| def test2() = "test2" | |
| def main (args: Array[String]): Unit = { | |
| println(test) | |
| // println(test()) // it's impossible | |
| println(test2) | |
| println(test2()) | |
| } |
This file contains hidden or 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
| class NewYear(y: Int) { | |
| val MinYear = 2014 | |
| require(y > MinYear) | |
| val year = y | |
| def this() = this(2015) | |
| override def toString = "Upcoming year is "+year | |
| } |
This file contains hidden or 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
| def gcd(a: Int, b: Int): Int = { | |
| if (b == 0) a else gcd(b, a % b) | |
| } |
This file contains hidden or 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
| def >:-> { println("That's awful!!!") } | |
| def main (args: Array[String]) { | |
| >:-> | |
| $greater$colon$minus$greater // this will also successful print awful message | |
| } |
This file contains hidden or 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 a = if (3 > 2) 5 else 6 | |
| val b = if (7 > 6) { 25; 4; 3 } else { 0 } |
This file contains hidden or 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
| var line = "" | |
| while ((line = file.readLine) != "") { | |
| println(line) | |
| } |
This file contains hidden or 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 inputFiles = new File("/somewhere/src").listFiles | |
| for { | |
| file <- inputFiles | |
| if file.isFile | |
| line <- scala.io.Source.fromFile(file).getLines() | |
| trimmed = line.trim | |
| if trimmed.matches(".*scala.*") | |
| } println(file+": "+trimmed) |
This file contains hidden or 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 a = try { | |
| throw new Exception | |
| 888 // it would't be result in value ever | |
| } catch { | |
| case ex: Exception => 777 | |
| } | |
| println(a) |
This file contains hidden or 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
| for ( | |
| file <- inputFiles | |
| if file.isFile | |
| ) { | |
| var ln = 0 | |
| for (line <- scala.io.Source.fromFile(file).getLines()) { | |
| ln += 1 | |
| if (line.matches(".*scala.*")) { | |
| println(file.getName+", "+ln+": "+line.trim) | |
| } |
This file contains hidden or 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
| for ( | |
| file <- inputFiles | |
| if file.isFile | |
| ) { | |
| val lines = scala.io.Source.fromFile(file).getLines().toList | |
| def grepScalaFrom(ln: Int): Unit = { | |
| if (ln >= lines.length) -1 | |
| else { | |
| if (lines(ln).matches(".*scala.*")) println(file+", "+(ln+1)+": "+lines(ln).trim) |