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
| import sbt._ | |
| import Keys._ | |
| object BaseSettings { | |
| val buildName = "MyProject" | |
| val buildOrg = "yagince" | |
| val buildVersion = "0.0.1" | |
| val buildScalaVersion = "2.10.1" | |
| val settings = Seq( |
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
| package interpolation | |
| object StringInterpolation_01 extends App { | |
| val hoge = "hoge" | |
| println(s"Hello $hoge!") | |
| } |
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
| package interpolation | |
| object StringInterpolation_02 extends App { | |
| println(s"${1 + 1}") | |
| def test = 1 + 1 | |
| println(s"${test}") | |
| println(s"$test") |
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
| package interpolation | |
| object StringInterpolation_03 extends App{ | |
| // format | |
| val pi = 3.14 | |
| val hoge = "hogehogehoge" | |
| println(f"$hoge is $pi%2.4f") // => hogehogehoge is 3.1400 | |
| //println(f"$hoge is $pi%2.4d") // これはpiがDoubleなので、エラーになる |
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
| package interpolation | |
| object StringInterpolation_04 extends App { | |
| println(s"100 + 1 = ${100+1}") // 100 + 1 = 101 | |
| println(StringContext("100 + 1 = ", "").s(100+1)) // 100 + 1 = 101 | |
| println(StringContext("100 + 1 = ", "%5d").f(100+1)) // 100 + 1 = 101 | |
| } |
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
| package implicitclass | |
| object ImplicitClass_01 extends App { | |
| implicit class DoubleInt(i: Int) { | |
| def double = i * 2 | |
| } | |
| println(1.double) | |
| class HalfInt(i: Int) { | |
| def half = i / 2 |
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
| package implicitclass | |
| object ImplicitClasses { | |
| implicit class TripleInt(i: Int) { | |
| def triple = i * 3 | |
| } | |
| } | |
| // こうは書けない | |
| //implicit class TripleInt(i: Int) { |
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
| package valueclass | |
| class Double(val i: Int) extends AnyVal with Hoge{ | |
| // val tmpDouble = i * 2 // これは定義できない | |
| def double = i*2 | |
| // 以下はコンパイルエラー | |
| // object Foo { | |
| // val foo = "foo" | |
| // } |
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
| package valueclass.implicitclass | |
| object ImplicitConversions { | |
| implicit class Triple(val i: Int) extends AnyVal { | |
| def triple = i * 3 | |
| } | |
| class Half(val i:Int) extends AnyVal { | |
| def half = i / 2 | |
| } | |
| implicit def toHalf(i: Int) = new Half(i) |
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
| package valueclass.memory.array | |
| object ValueClass_04 extends App { | |
| case class Hoge(val hoge: String) extends AnyVal | |
| val hoge = Hoge("aaaa").hoge | |
| val array = Array[Hoge](Hoge("str")) | |
| val list = List[Hoge](Hoge("str")) | |
| val seq = Seq[Hoge](Hoge("str")) | |
| val set = Set[Hoge](Hoge("str")) |
OlderNewer