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
// 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) |
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
// 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) |
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
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) |
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
[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 |
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
[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 |
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 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)) |
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
set nocompatible " must be the first line | |
filetype on | |
filetype indent on | |
filetype plugin on | |
"" General options | |
set bg=dark | |
syntax on | |
set number |
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 patmat | |
import scala.language.postfixOps | |
import common._ | |
/** | |
* Assignment 4: Huffman coding | |
* | |
*/ | |
object Huffman { |
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
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 | |
} | |
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
%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) | |
} |
OlderNewer