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
| import java.util.concurrent.atomic.AtomicInteger | |
| import akka.actor._ | |
| import akka.actor.Actor._ | |
| import akka.dispatch.Future | |
| case class Reduce(val size: Int) | |
| case class MappingDetail[T](val item: T, val reducer: ActorRef) | |
| class MapperActor[T, U](val mapping: (T) => U) extends Actor { |
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
| object Unless { | |
| def unless[T](test:Boolean)(code: => T) = { if (!test) code } | |
| } | |
| import Unless._ | |
| unless(seq.isEmpty) { | |
| println("We gots us some stuff!") | |
| } |
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
| 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 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
| import scala.util.parsing.combinator._ | |
| class IrcParser extends RegexParsers { | |
| /* | |
| RFC1459 2.3.1 Message format in 'pseudo' BNF | |
| <message> ::= [':' <prefix> <SPACE> ] <command> <params> <crlf> |
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
| /** | |
| * Garrick Evans | |
| * 29 Dec 2010 | |
| */ | |
| import akka.http._ | |
| import akka.actor._ | |
| import net.smartam.leeloo.client._ | |
| import net.smartam.leeloo.client.request.OAuthClientRequest | |
| import net.smartam.leeloo.client.response. {OAuthAuthzResponse, GitHubTokenResponse} |
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
| scala> import net.debasishg.domain.trade.dsl._ | |
| import net.debasishg.domain.trade.dsl._ | |
| scala> import Trades._ | |
| import Trades._ | |
| scala> import scalaz._ | |
| import scalaz._ | |
| scala> import Scalaz._ |
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
| object WordCount { | |
| def main(args: Array[String]) { | |
| import mapreduce._ | |
| import _root_.scala.io.Source | |
| def textInputFormat(lines: Iterator[String], offset: Long = 0): Stream[(Long, String)] = { | |
| if(lines.hasNext) { | |
| val line = lines.next |
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
| /** | |
| * An answer from Jason Zaugg on the scala-internals mailing list | |
| * | |
| * Implicit parameters can have defaults. | |
| */ | |
| scala> implicit def OptionalImplicit[A <: AnyRef](implicit a: A = null) = Option(a) | |
| OptionalImplicit: [A <: AnyRef](implicit a: A)Option[A] | |
| scala> implicitly[Option[Ordering[Int]]] |
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
| // joining of 2 arrows | |
| (>>>) :: arr a b -> arr b c -> arr a c | |
| (>>>) | |
| a -- (f) --> b -- (g) --> c | |
| // works on pairs | |
| // f: a -> b | |
| // g: a -> c |
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
| scala> val l = List(1,2,3) | |
| l: List[Int] = List(1, 2, 3) | |
| // pattern matching | |
| scala> l match { | |
| | case s if s.forall(even(_)) => Some(l) | |
| | case _ => None | |
| | } | |
| res37: Option[List[Int]] = None |