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
package org.example | |
import org.apache.log4j.Logger | |
object Log4jproject extends App { | |
val logger: Logger = Logger.getLogger(this.getClass.getName) | |
logger.info("log4j test") | |
} |
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
val op: Pair[BigInt, BigInt] = Pair(1, 1) | |
(0 until 10).foldLeft(op) { (ab, x) => | |
println(ab._1) | |
Pair[BigInt, BigInt](ab._2, ab._2 + ab._1) | |
} |
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.control.Exception._ | |
object Main { | |
def main(args : Array[String]) : Unit = { | |
args.toList.filter(allCatch either _.toInt isRight).sorted.foreach(println) | |
} | |
} | |
// 数値かどうかをチェックするのに、toInt関数を呼んで例外が発生するかどうかでチェックするとか | |
// 良いやりかたでは無いと思います。 |
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 sbt._ | |
import sbt.Keys._ | |
object Scala210Build extends Build { | |
lazy val scala210 = Project( | |
id = "scala-210", | |
base = file("."), | |
settings = Project.defaultSettings ++ Seq( | |
name := "Scala 210", |
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 scalaz._, Scalaz._ | |
import java.util.Date | |
case class Student(name: String, grade: Int, birthday: Date) | |
object Student { | |
implicit object StudentInstance extends Show[Student] with Order[Student] { | |
def show(s: Student) = s.toString.toList | |
def order(s1: Student, s2: Student) = | |
s1.grade ?|? s2.grade |+| s1.birthday ?|? s2.birthday | |
} |
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
def string2Int(sizeString: Option[String]): Option[Int] = { | |
sizeString match { | |
case Some(a) => | |
try { | |
val size = a.toInt | |
Option(size) | |
} catch { | |
case _ => | |
None | |
} |
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 org.specs2.mutable._ | |
import org.specs2.specification._ | |
import org.mockito.Mockito._ | |
import com.mongodb.casbah.Imports._ | |
import com.twitter.finagle.http._ | |
import com.twitter.finagle.http.path._ | |
import com.twitter.finagle.{ Service, Filter, SimpleFilter } | |
import com.twitter.util.{ Future, FuturePool, Eval } | |
import scala.util.control.Exception._ |
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 com.twitter.sbt._ | |
organization := "com.example" | |
name := "Finagle Http Project" | |
version := "0.1.0" | |
scalaVersion := "2.9.2" |
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
val addUmm: String => String = _ + " umm" | |
val addAhem: String => String = _ + " ahem" | |
val ummThenAhem = addAhem.compose(addUmm) | |
def addUmm2(x: String) = x + " umm" | |
def addAhem2(x: String) = x + " ahem" | |
val ummThenAhem2 = (addAhem2 _).compose(addUmm2 _) |
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
List(Random.nextInt(size), Random.nextInt(size), Random.nextInt(size)) | |
// はもうちょっとかっこよくかける気がする。 |