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
abstract class some[X](val value : X) { type T = X } | |
abstract class someFactory[S <: some[_]](val P : (S#T) => boolean) | |
{ | |
def apply(t : S#T) : Option[S] = if(P(t)) Some(fetch(t)) else None | |
def unapply(s : S) : Option[S#T] = if(s == null) None else Some(s.value) | |
def fetch(t : S#T) = mk(t) |
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
//isValid = predicate/constraint | |
abstract class Type[T](val isValid : (T) => boolean) | |
{ | |
//X is the reference type | |
final protected[Type] case class X[T] (val value : T) { | |
override def toString = Type.this.getClass.getSimpleName + "(" + value + ")" | |
} | |
//Type is the alias for X[T] that we expose to the outside world | |
type Type = X[T] |
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
object Test { | |
trait Mapping { | |
def get[T](clazz : Class[T]) : T | |
} | |
trait Injector { | |
protected val mapping : Mapping | |
def inject[T](implicit manifest : scala.reflect.Manifest[T]) = mapping.get(manifest.erasure.asInstanceOf[Class[T]]) | |
} |
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 dining.hakkers | |
//Akka adaptation of | |
//http://www.dalnefre.com/wp/2010/08/dining-philosophers-in-humus/ | |
import se.scalablesolutions.akka.actor.{Scheduler, ActorRef, Actor} | |
import se.scalablesolutions.akka.actor.Actor._ | |
import java.util.concurrent.TimeUnit | |
/* |
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 my.concurrent.multimap | |
import scala.reflect.Manifest | |
import java.util.concurrent.{ConcurrentSkipListSet, ConcurrentHashMap} | |
import java.util.{Set => JSet} | |
import scala.collection.JavaConversions._ | |
import annotation.tailrec | |
class Index[K <: AnyRef,V <: AnyRef : Manifest] { |
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
//Usage: | |
//override def pomPostProcess(node: Node): Node = mcPom(moduleConfigurations)(super.pomPostProcess(node)) | |
trait McPom { self: DefaultProject => | |
import scala.xml._ | |
def mcPom(mcs: Set[ModuleConfiguration])(node: Node): Node = { | |
//make sure we have a trailing slash so we deduplicate URLs properly | |
def cleanUrl(url: String) = url match { | |
case null => "" |
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
/** | |
* I had a question directed at me, on how to encode the following scenario in Akka Actors, | |
* as for Scala Actors one would simply nest the receives. | |
* | |
* Recuirements are as follows: | |
* The first thing the actor needs to do, is to subscribe to a channel of events, | |
* Then it must replay (process) all "old" events | |
* Then it has to wait for a GoAhead signal to begin processing the new events | |
* It mustn't "miss" events that happen between catching up with the old events and getting the GoAhead signal | |
*/ |
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 scala.collection.mutable.ListBuffer | |
import akka.actor.{Actor,ActorRef} | |
import akka.actor.Actor._ | |
import akka.routing.{ Listeners, Listen } | |
//Represents a domain event | |
trait Event | |
//A builder to create domain entities | |
trait EntityBuilder[Entity] { |
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 MiniSTM[T <: AnyRef](initialValue: T) { | |
private val value = new AtomicReference[T](initialValue) | |
def apply(fun: T => T) { | |
@tailrec def update(expect: T): Unit = | |
if ( !value.compareAndSet(expect, fun(expect)) ) update(value.get) | |
update(value.get) | |
} | |
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
trait PostStart { actor: Actor => | |
def postStart: Unit | |
override def preStart { | |
actor.become { | |
case "PostStart" => try { postStart } finally { actor.unbecome } | |
} | |
actor.self ! "PostStart" | |
} | |
} |
OlderNewer