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
//My take on: http://solog.co/47/10-scala-one-liners-to-impress-your-friends/ | |
//1. Multiple Each Item in a List by 2 | |
//(1 to 10) map { _ * 2 } | |
(1 to 10) map (2*) | |
//2. Sum a List of Numbers | |
//(1 to 1000).reduceLeft( _ + _ ) | |
(1 to 1000).sum |
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 flatTraverse[T](node: Node)(pfn: PartialFunction[Node, TraversableOnce[T]]): Seq[T] = { | |
traverse(node)(pfn).flatten | |
} | |
def traverse[T](node: Node)(pfn: PartialFunction[Node, T]): Seq[T] = { | |
def inner(n: Node, acc: List[T]): List[T] = n match { | |
case x if (pfn isDefinedAt x) => pfn(x) :: acc | |
case e: Elem => (e.child.toList map {inner(_, Nil)}).flatten ::: acc | |
case _ => acc | |
} |
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
class Filters[T] { | |
//Some boilerplate-busting aliases | |
type FilterResult = Either[Rejection, T] | |
type FilterFunc = (T) => FilterResult | |
//Handy helpers | |
//Rejection can carry as much info as you wish; | |
// Filter name, value in error, an exception, etc. | |
case class Rejection(input: T, msg: String) |
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 + + [B>: A, That] (that: TraversableOnce [B]) (implicit bf: CanBuildFrom [List [A], B, That]): That |
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.zeebox.starwatch | |
import javax.servlet.{ServletContextEvent, ServletContextListener} | |
import java.net.InetAddress | |
import akka.actor.ActorSystem | |
import cc.spray.SprayServletSettings | |
import akka.config.ConfigurationException | |
import akka.util.{Reflect, Switch} | |
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.zeebox.starwatch | |
import akka.actor.ActorSystem | |
import akka.util.Reflect | |
import java.net.InetAddress | |
import com.typesafe.config.ConfigFactory | |
import org.slf4j.LoggerFactory | |
object ActorSystemFactory { | |
val log = LoggerFactory.getLogger(this.getClass) |
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 ZeeingEvent( | |
zid: String, | |
kind: String, | |
showId: String, | |
show_name: Option[String], | |
time: DateTime | |
) { | |
require (kind == "StartedZeeing" || kind == "EndedZeeing") | |
} |
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
import akka.dispatch.{ExecutionContext, Future, Promise} | |
import collection.generic.CanBuildFrom | |
def linearise[T, U, C[T] <: Traversable[T]](s: C[T])(f: T => Future[U])(implicit cbf: CanBuildFrom[C[T], Future[U], C[Future[U]]], e: ExecutionContext): C[Future[U]] = { | |
val builder = cbf(s) | |
var prevPromise: Promise[_] = Promise[Unit] success () |
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
import akka.agent.Agent | |
import shapeless.Lens | |
import concurrent.Future | |
import akka.util.Timeout | |
import concurrent.ExecutionContext | |
object FocusedAgent { | |
implicit class EnrichedAgent[A](val agent: Agent[A]) extends AnyVal { | |
def focusOn[B](lens: Lens[A,B]): FocusedAgent[A,B] = new FocusedAgent[A,B](agent, lens) | |
} |
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
import akka.agent.Agent | |
import akka.util.Timeout | |
import akka.actor.ActorSystem | |
import concurrent.{Future, Promise} | |
import concurrent.duration.FiniteDuration | |
import shapeless.Lens | |
object Signal { |