step1
パラメータを受け取るコントローラを作る
object Application extends Controller {
def parameterExample(parameter: String) = Action {
Ok(views.html.index(parameter))
}
}
trait hentaiConverter { | |
implicit def stringToHentaiChecker(s: String) = HentaiChecker(s) | |
case class HentaiChecker(s: String) { | |
def isHentai: Boolean = s == "変態" | |
} | |
} |
trait hentaiConverter { | |
implicit def stringToHentaiChecker(s: String) = HentaiChecker(s) | |
case class HentaiChecker(s: String) { | |
def hentaiPower: Int = { | |
import scala.io.Source | |
val contents = Source.fromURL("http://www.google.co.jp/search?q=変態+%s".format(s), "utf8").getLines.mkString | |
val searchCountPattern = "約? ?([0-9,]+) ?件".r |
List list = [ | |
[color:"blue", weight:10], | |
[color:"red", weight:30], | |
[color:"blue", weight:50], | |
] | |
// Javaで | |
int weight1 = 0; | |
for (def e : list) { | |
if ("blue".equals(e.color)) |
case class irof (formula: Boolean)(irofBlock: => Unit) { | |
formula match { | |
case true => irofBlock | |
case _ => | |
} | |
def elof(elofBlock: => Unit): Unit = { | |
formula match { | |
case false => elofBlock |
(BigInt(100) to BigInt(1) by -1).reduce((x, y) => x * y).toString.toList.map(_.getNumericValue).sum |
def maxPrime(n: Int) = { | |
def isPrime(n: Int) = Iterator.from(2).takeWhile(p => p * p <= n).forall(p => n % p != 0) | |
(1 to n).filter(isPrime).max | |
} |
// http://odz.sakura.ne.jp/projecteuler/index.php?cmd=read&page=Problem%2025 | |
// http://projecteuler.net/problem=25 | |
val fib:Stream[BigInt] = BigInt(1) #:: fib.scanLeft(BigInt(1)){(a, b) => a + b } | |
def getDigits = (n: BigInt) => n.toString.size | |
fib.takeWhile(getDigits(_) <= 1000).zipWithIndex.find(t => getDigits(t._1) == 1000).get._2 + 1 |
// コードを読みやすいように名前をつけとこう. | |
val Up = 0 | |
val Right = 1 | |
val Down = 2 | |
val Left = 3 | |
type Direction = Int | |
/* | |
* 石像をあらわすcase class. 像の向きを状態として持つ. | |
* また、一回の動作で向きが90度回転するという振る舞いも定義. |
package util | |
import java.util.Date | |
import java.text.SimpleDateFormat | |
object DateUtil { | |
implicit class StringToDate(self: String) { | |
/** | |
* フォーマット指定された形式でDate型に変換する | |
* |
step1
パラメータを受け取るコントローラを作る
object Application extends Controller {
def parameterExample(parameter: String) = Action {
Ok(views.html.index(parameter))
}
}