Skip to content
Browse files

Initial commit of scala/sbt/git template

  • Loading branch information...
0 parents commit 75f5aa60275b09eb0a196c791d9e44717c140fe4 @fedesilva committed
Showing with 86 additions and 0 deletions.
  1. +4 −0 .gitignore
  2. +31 −0 build.sbt
  3. +6 −0 project/plugins.sbt
  4. +45 −0 src/main/scala/main.scala
4 .gitignore
@@ -0,0 +1,4 @@
+target/
+.history
+
+
31 build.sbt
@@ -0,0 +1,31 @@
+import AssemblyKeys._ // put this at the top of the file
+
+name := "akka-load-balancing"
+
+version := "1.0"
+
+scalaVersion := "2.9.1"
+
+seq(assemblySettings: _*)
+
+libraryDependencies ++= Seq( "se.scalablesolutions.akka" % "akka-actor" % "1.3.1",
+ "org.specs2" %% "specs2" % "1.7.1" % "test" )
+
+resolvers ++= Seq(
+ "Typesafe Repository" at "http://repo.typesafe.com/typesafe/releases/",
+ "jGit Repository" at "http://download.eclipse.org/jgit/maven",
+ "Local Repository" at "file://"+Path.userHome.absolutePath+"/.m2/repository" )
+
+resolvers += Resolver.url("sbt-plugin-releases",
+ new URL("http://scalasbt.artifactoryonline.com/scalasbt/sbt-plugin-releases/"))(Resolver.ivyStylePatterns)
+
+
+scalacOptions ++= Seq(
+ "-deprecation",
+ "-unchecked",
+ "-Xmigration",
+ "-Xcheckinit",
+ "-optimise",
+ "-encoding", "utf8"
+)
+
6 project/plugins.sbt
@@ -0,0 +1,6 @@
+addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.7.3")
+
+resolvers += Resolver.url("sbt-plugin-releases",
+ new URL("http://scalasbt.artifactoryonline.com/scalasbt/sbt-plugin-releases/"))(Resolver.ivyStylePatterns)
+
+
45 src/main/scala/main.scala
@@ -0,0 +1,45 @@
+package templated
+
+object Main {
+
+ import Combinators._ //Import all members of Combinators into scope.
+
+ final val Default = 5 //We use FirstCaps to denote constants.
+
+ def main(args:Array[String]) {
+
+ //Try/catch blocks are expressions.
+ val itemCount = try {
+ //An array is like any other collection and you can lift the values to an option
+ args.lift(0).getOrElse("99").toInt
+ }
+ catch handleNotNumber orElse handleError // catch blocks are generalized and can use partial functions.
+
+ //We use implicits ( import Combinators._ ) to use |>
+ val list = makeAListOf( itemCount ) |> reverse
+ println( "I do nothing except creating lists like this " + list );
+
+ }
+
+ def makeAListOf(count:Int) = (1 to count) toList // Nice collections api!
+ def reverse[T](list:List[T]) = list reverse
+
+ def handleNotNumber: PartialFunction[Throwable,Int] = {
+ case nfe:NumberFormatException => 5 //This is an expression
+ }
+
+ def handleError: PartialFunction[Throwable,Int] = {
+ case e =>
+ println("Something went wrong: "+e.getMessage);
+ sys.exit(2)
+ }
+
+}
+
+object Combinators {
+ class Combinator[T](res:T) {
+ def |>[R]( fun:Function1[T,R] ): R = fun(res)
+ }
+ implicit def TtoCombinator[T](res:T):Combinator[T] = new Combinator(res)
+}
+

0 comments on commit 75f5aa6

Please sign in to comment.
Something went wrong with that request. Please try again.