Scalaの記事です。Haskellはあまり書けません。
Iterateeの複雑さから開放されたいのでPipe系ライブラリ使いましょうという記事です。
Iterateeとの比較や簡単な使い方についてつらつらと書いていきます。
package play.api.i18n | |
import play.api._ | |
import play.api.i18n._ | |
import scala.collection.JavaConverters._ | |
import scalax.file._ | |
import scalax.io.JavaConverters._ |
以下がインストールされているものとする。
def cond[A](value: A)(f: PartialFunction[A, SQLBuilder => SQLBuilder]): SQLBuilder
こんな感じの(実際にはSQLBuilderはサブクラス型にしないとだけど)あれば下みたいに書けるかなー
val id: Option[Int] = ...
val name: Option[String] = ...
class MyManagedResource extends ResourceController[String] { | |
def index = Action(Ok("index")) | |
def newScreen = Action(Ok("new")) | |
def create = Action { | |
Redirect(MyInjectableResource.reverseRoutes.index()) | |
} | |
def show(id: String) = Action(Ok("Show " + id)) |
// create an index with an analyzer "myindex" | |
curl -X PUT localhost:9200/myindex -d ' | |
{ | |
"settings" : {` | |
"index":{ | |
"number_of_replicas":0, | |
"number_of_shards":1, | |
"analysis":{ | |
"analyzer":{ | |
"first":{ |
object RetryUtil { | |
case class RetryException(throwables: List[Throwable]) extends Exception | |
def retry[T](retryLimit: Int, retryInterval: Int, shouldCatch: Throwable => Boolean)(f: => T): T = { | |
// @annotation.tailrec | |
def _retry( errors: List[Throwable], f: => T):T = { | |
try { | |
f | |
} catch { |
def index(id:String) = Action { | |
getFirstData(id) | |
} | |
private def getFirstData(id:String) = { | |
Cache.get(id) match { | |
case Some(id2) => getSecondData(id2) | |
case None => NotFound | |
} | |
} | |
private def getSecondData(id2:String) = { |