Skip to content

Instantly share code, notes, and snippets.

// type WithOID = { def id: ObjectId }
trait WithOID { def id: ObjectId }
sealed trait QueryParams[WithOID]
case class All[WithOID]() extends QueryParams[WithOID]
case class Paginated[Song](pageSize: Int, pageOffset: Int,
from: Option[Song] = None) extends QueryParams[WithOID] {
def enrich(criteria: MongoDBObject) =
from map { a =>
criteria ++ {
if (pageOffset >= 0)
// type WithOID = { def id: ObjectId }
trait WithOID { def id: ObjectId }
sealed trait QueryParams[WithOID]
case class All[WithOID]() extends QueryParams[WithOID]
case class Paginated[WithOID](pageSize: Int, pageOffset: Int,
from: Option[WithOID] = None) extends QueryParams[WithOID] {
def enrich(criteria: MongoDBObject) =
from map { a =>
criteria ++ {
if (pageOffset >= 0)
type WithOID = { def id: ObjectId }
// trait WithOID { def id: ObjectId }
sealed trait QueryParams[WithOID]
case class All[WithOID]() extends QueryParams[WithOID]
case class Paginated[WithOID](pageSize: Int, pageOffset: Int,
from: Option[{def id: ObjectId}] = None) extends QueryParams[WithOID] {
def enrich(criteria: MongoDBObject): MongoDBObject =
from.map { x: {def id: ObjectId } =>
criteria ++ {
if (pageOffset >= 0)
@behaghel
behaghel / mvn-scala-output-expected
Created August 18, 2011 12:43
davidB/maven-scala-plugin#57 illustration
[INFO] [scala:compile {execution: default}]
[INFO] Checking for multiple versions of scala
[INFO] includes = [**/*.scala,**/*.java,]
[INFO] excludes = []
[INFO] /home/hub/p/eee/src/main/scala:-1: info: compiling
[INFO] Compiling 128 source files to /home/hub/p/eee/target/classes at 1312794546514
[INFO] Recompiling 1 files
[ERROR] /home/hub/p/eee/src/main/scala/Service.scala:72: error: type mismatch;
[ERROR] found : Unit
[ERROR] required: () => Any
@behaghel
behaghel / mvn-scala-output-actual
Created August 18, 2011 12:44
davidB/maven-scala-plugin#57 illustration
[INFO] [scala:compile {execution: default}]
[INFO] Checking for multiple versions of scala
[INFO] includes = [**/*.scala,**/*.java,]
[INFO] excludes = []
[INFO] /home/hub/p/eee/src/main/scala:-1: info: compiling
[INFO] Compiling 128 source files to /home/hub/p/eee/target/classes at 1312794546514
[INFO] Recompiling 1 files
[ERROR] /home/hub/p/eee/src/main/scala/Service.scala:72: error: type mismatch;
[INFO] found : Unit
[INFO] required: () => Any
case class Person(firstname: String, lastname: String)
type MongoReader[T] = MongoDBObject => T
type MongoWriter[T] = T => MongoDBObject
def readArray[T : MongoReader](name: String) = new MongoReader[List[T]] {
def apply(dbo: MongoDBObject) = {
println("dbo = %s".format(dbo.toString))
println("dbo.%s = %s".format(name, dbo.as[BasicDBList](name).toString))
set nocompatible " must be the first line
filetype on
filetype indent on
filetype plugin on
"" General options
set bg=dark
syntax on
set number
package patmat
import scala.language.postfixOps
import common._
/**
* Assignment 4: Huffman coding
*
*/
object Huffman {
implicit class RichMap[K, V](m: Map[K, V]) {
def updateValue(k: K)(f: Option[V] => V): Map[K, V] = m + (k -> f(m get k))
def incValue(k: K)(implicit ev: Numeric[V]): Map[K, V] =
updateValue(k){ o =>
val one = ev.fromInt(1)
o map { ev.plus(_, one) } getOrElse one
}
%s should %s be balanced".format(s,
if (!expected) "NOT" else ""))
testBalance("(if (zero? x) max (/ 1 x))")
testBalance("I told him (that it's not (yet) done)." +
"(But he wasn’t listening)")
testBalance(":-)", expected = false)
testBalance("())(", expected = false)
}