language is representation (data structures) and combination (control structures)
goals of a language: simplification => easy to express "what" it is you're trying to do
simplification => generalization
towards composability
| scala> import xml._ | |
| import xml._ | |
| scala> class Attr(name: String) { def unapply(e: Elem) = e.attribute(name).map(_.text) } | |
| defined class Attr | |
| scala> val IdAttr = new Attr("id") | |
| IdAttr: Attr = Attr@6b2dc21d | |
| scala> <a id="123"/> match { case IdAttr("123") => "!" }res3: java.lang.String = ! |
| // Usage: | |
| // p(instance)('privateMethod)(arg1, arg2, arg3) | |
| class PrivateMethodCaller(x: AnyRef, methodName: String) { | |
| def apply(_args: Any*): Any = { | |
| val args = _args.map(_.asInstanceOf[AnyRef]) | |
| def _parents: Stream[Class[_]] = Stream(x.getClass) #::: _parents.map(_.getSuperclass) | |
| val parents = _parents.takeWhile(_ != null).toList | |
| val methods = parents.flatMap(_.getDeclaredMethods) | |
| val method = methods.find(_.getName == methodName).getOrElse(throw new IllegalArgumentException("Method " + methodName + " not found")) |
| import akka.amqp.AMQP._ | |
| import akka.amqp._ | |
| import akka.actor._ | |
| import java.util.concurrent.{TimeUnit, CountDownLatch} | |
| import util.Random | |
| object LoadBalancingDemo { | |
| def main(args: Array[String]) { |
| <?xml version="1.0" encoding="UTF-8"?> | |
| <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
| <plist version="1.0"> | |
| <dict> | |
| <key>Label</key> | |
| <string>org.mongodb.mongod</string> | |
| <key>ProgramArguments</key> | |
| <array> | |
| <string>/usr/local/mongodb/bin/mongod</string> | |
| <string>run</string> |
| import java.io.File | |
| import sbt._ | |
| class Project(info: ProjectInfo) extends ParentProject(info) with IdeaProject { | |
| lazy val mavenLocal = "Local Maven Repository" at "file://"+Path.userHome+"/.m2/repository" | |
| lazy val geotoolsRepository = "Open Source Geospatial Foundation Repository" at "http://download.osgeo.org/webdav/geotools/" | |
| lazy val javanetRepository = "Java.net Repository" at "http://download.java.net/maven/2" | |
| lazy val iglootoolsRepository = "Iglootools Releases Repository" at "http://developers.sirika.com/maven2/releases/" | |
| lazy val jbossRepository = "JBoss Releases Repository" at "https://repository.jboss.org/nexus/content/groups/public-jboss" | |
| lazy val hibernateSpatial = "Hibernate Spatial Repository" at "http://www.hibernatespatial.org/repository" |
| // initial version | |
| import scala.collection.immutable.TreeSet | |
| class TreeMember[A] { | |
| // some really important stuff here, of course! ;~) | |
| } | |
| class Main { | |
| implicit val treeOrder = new Ordering[TreeMember[A]] { | |
| def compare(a: TreeMember[A], b: TreeMember[A]) = { | |
| // elided for simplicity's sake | |
| } |
| trait Builder[M[_], N[_]] { | |
| type Apply[T] = M[N[T]] | |
| } | |
| implicit def optionIntListBuilder: Builder[List, Option]#Apply[Int] = List.empty[Option[Int]] | |
| // make a list of option[T] | |
| def make[T](implicit p: Builder[List, Option]#Apply[T]): List[Option[T]] = p | |
| make[Int] // List[Option[Int]] |
| // ########################################################### | |
| // | |
| // Demonstrates how to supervise an Akka consumer actor. | |
| // | |
| // The consumer consumes messages from a file endpoint: | |
| // - successful message processing by the consumer will | |
| // positively acknowledge the message receipt, causing | |
| // the file endpoint to delete the file. | |
| // - an exception during message processing will cause a | |
| // supervisor to restart the consumer. Before restart, |
| 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] { |