Skip to content

Instantly share code, notes, and snippets.

View id-ilych's full-sized avatar

Ilya Denisov id-ilych

View GitHub Profile
@id-ilych
id-ilych / EitherTest.scala
Last active April 29, 2019 14:43
Before/after (Either)
// before
override def receive(ev: AnyRef)(implicit self: ItemValue) = ev match {
case ev: MsgItems.ApplyAction if ev.getChoice == ActionChoice.Activate =>
if (ev.getArgsCount > 0) {
val arg = ev.getArgs(0)
cfg.targets.lift(arg) match {
case Some(target) =>
items.syncBroadcast(SyncToolForUpgrade(typeId = target.toolTypeId)).info match {
case Some(tool) =>
target.nextUpgrade(upgradesHave = tool.upgrades) match {
@id-ilych
id-ilych / ParamReader.scala
Last active February 16, 2016 18:17
Helper methods for getting/applying request params
trait Request {
def getParam(key: String): String
def getCommaParamList(key: String): Seq[String]
def paramOpt[T](key: String)(implicit reader: ParamReader[T]): Option[T] = Option(getParam(key)).map(reader.read)
def paramOpt[T](key: String, op: T => _)(implicit reader: ParamReader[T]): Unit = paramOpt(key).foreach(op)
def param[T](key: String)(implicit reader: ParamReader[T]): T = reader.read(getParam(key))
def param[T](key: String, op: T => _)(implicit reader: ParamReader[T]): Unit = op(param(key))
def paramExists(key: String): Boolean = getParam(key) != null
def paramExists(key: String, op: Boolean => _): Unit = op(paramExists(key))