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 com.kinja.foo.bar |
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
sealed trait Expr | |
case class Num(n: Int) extends Expr | |
case class Add(e1: Expr, e2: Expr) extends Expr | |
case class Sub(e1: Expr, e2: Expr) extends Expr | |
def value(e: Expr): Int = e match { | |
case Num(n) => n | |
case Add(e1, e2) => value(e1) + value(e2) | |
case Sub(e1, e2) => value(e1) - value(e2) | |
} |
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
sealed trait Expr { | |
def value: Int | |
} | |
case class Num(n: Int) extends Expr { | |
def value = n | |
} | |
case class Add(e1: Expr, e2: Expr) extends Expr { | |
def value = e1.value + e2.value | |
} | |
case class Sub(e1: Expr, e2: Expr) extends Expr { |
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
trait Value[T] { | |
def eval(e: T): Int | |
} | |
def value[T: Value](e: T) = implicitly[Value[T]].eval(e) | |
sealed trait Expr | |
case class Num(n: Int) extends Expr |
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 getSpeedByDistanceAndTime(x: Int, y: Int) = x / y |
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 speed(distance: Distance, time: Time) = | |
Speed(distance.value / time.value) |
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
flag match { | |
case true => f() | |
case false => g() | |
} |
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
if (flag) f() else g() |
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
case class BlogMeta( | |
description: Option[String] = None, | |
descriptionHtml: Option[String] = None, | |
timezone: String = "America/New_York", | |
properties: Option[String] = None, | |
adminProperties: Option[String] = None, | |
showLikesInLatest: Option[Boolean] = None, | |
showRepliesInLatest: Option[Boolean] = None, | |
features: List[String] = List(), | |
groupBlog: Option[Boolean] = None) |
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
list.map(f) | |
list.map { element => | |
something() | |
f(element) | |
somethingElse() | |
} | |
list.map { | |
case Data(d) => f(d) |