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
object Speed { | |
implicit def Int2Speed(value: Int): Speed = new Speed(value) | |
} | |
case class Speed(value: Int) { | |
def km_hour: Speed = this |
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
import com.hdbandit.dsl.Speed._ | |
object Robot { | |
def newRobot(initialXposition: Int = 0, initialYposition: Int = 0): Robot = new Robot(initialXposition, initialYposition) | |
} | |
class Robot(initialXposition: Int, initialYposition: Int) { |
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
import Robot._ | |
import Speed._ | |
object RobotApp { | |
def main(args: Array[String]): Unit = { | |
// scala style | |
val robot = newRobot(0, 0) |
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 robot = newRobot(0, 0) | |
robot at 30.km_hour towards (20, 15) go | |
robot at 60.km_hour towards (60, 15) go | |
robot at 2.meters_second towards (22, 17) go |
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
object Rational { | |
implicit def intToRational(x: Int) = new Rational(x) | |
} | |
class Rational(n: Int, d: Int) { | |
require(d != 0, "Denominator cannot be 0") | |
println("My rational is created") | |
val num = n |
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
class Rational(n: Int, d: Int) { | |
require(d != 0, "Denominator cannot be 0") | |
println("My rational is created") | |
val num = n | |
val denom = d | |
def this(n: Int) = this(n, 1) | |
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
class Rational(n: Int, d: Int) { | |
require(d != 0, "Denominator cannot be 0") | |
println("My rational is created") | |
val num = n | |
val denom = d | |
def this(n: Int) = this(n, 1) | |
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
class Rational(n: Int, d: Int) { | |
require(d != 0, "Denominator cannot be 0") | |
println("My rational is created") | |
val num = n | |
val denom = d | |
override def toString = s"$n/$d" |
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
class Rational(n: Int, d: Int) { | |
require(d != 0, "Denominator cannot be 0") | |
println("My rational is created") | |
override def toString = s"$n/$d" | |
} |
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
object MyCoolApp { | |
def main(args: Array[String]): Unit = { | |
val myColor = Color.create(23, 14, 9) | |
println("Initial color: " + myColor) | |
val inverseColor1 = !myColor | |
println("Inverse color: " + inverseColor1) |
NewerOlder