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 CanFromString[T] { | |
def fromString(s: String): T | |
} | |
implicit object intCanFromString extends CanFromString[Int] { | |
override def fromString(s: String): Int = s.toInt | |
} | |
implicit object SymbolCanFromString extends CanFromString[Symbol] { | |
override def fromString(s: String): Symbol = Symbol(s) | |
} |
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 module.db; | |
import com.mongodb.casbah.Imports._ | |
import java.text.DateFormat | |
import java.util.Date | |
import play.api.data.validation.ValidationError | |
import play.api.libs.json._ | |
object MongoJson { | |
def fromJson(json: JsValue) : JsResult[DBObject] = readDBObject.reads(json) |
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 myFunc() = { | |
val rs = calcSomeResult() | |
logger.info("result is:" + rs) | |
rs | |
} | |
为避免上面的麻烦写法: | |
object LogUtil { | |
def kestrel[A](x: A)(f: A => Unit): A = { f(x); x } | |
def logV[A](f: String => Unit)(s: String, x: A) = kestrel(x) { y => f(s + ": " + y) } |