Skip to content

Instantly share code, notes, and snippets.

View HDBandit's full-sized avatar

Gerard Vico HDBandit

View GitHub Profile
object Speed {
implicit def Int2Speed(value: Int): Speed = new Speed(value)
}
case class Speed(value: Int) {
def km_hour: Speed = this
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) {
import Robot._
import Speed._
object RobotApp {
def main(args: Array[String]): Unit = {
// scala style
val robot = newRobot(0, 0)
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
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
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)
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)
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"
class Rational(n: Int, d: Int) {
require(d != 0, "Denominator cannot be 0")
println("My rational is created")
override def toString = s"$n/$d"
}
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)