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
package org.pblue.treee | |
case class Node[T](var value: T, var children: List[Node[T]]) | |
trait Treee[T] { | |
val root: Node[T] | |
def filter(pred: T => Boolean): List[Node[T]] |
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
case class Node(level: Int, value: String, children: List[Node]) | |
// This returns a pair of lists, which of the first one is the result, | |
// and given the constraints on the input, must always have only one element. | |
// The second list must always be empty in the end result. | |
def build(input: List[(Int, String)]): (List[Node], List[Node]) = | |
input match { | |
case Nil => (Nil, Nil) | |
case (level, value)::Nil => (List(Node(level, value, List())), Nil) | |
case (level, value)::tail => |
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
case class PermalinkPageData( | |
post: Post, | |
comments: ReplyList, | |
sidebar: Sidebar) | |
class PermalinkPageDataSoy extends SoyWrites[PermalinkPageData] { | |
def toSoy: Future[SoyMap] = Soy.future { | |
"post" -> post.toSoy, | |
"comments" -> comments.toSoy, | |
"sidebar" -> sidebar.render.map(SoyString(_)) |
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
trait SectionData | |
object Render { | |
def map(items: (String, Future[SoyValue])*): Seq[(String, Future[SoyValue])] = items | |
} | |
implicit class Renderable[T : Renderer[T]](data: T) { | |
def soy(template: String): Future[SoyValue] = implicitly[Renderer[T]].soy(template, data) | |
def html(template: String): Future[String] = implicitly[Renderer[T]].html(template, data) | |
} |
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
package com.kinja.foo | |
package bar |
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
package com.kinja.foo.bar |
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
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 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 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 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 |
OlderNewer