- オブジェクト指向パラダイムを主軸に関数型パラダイムを取り込んだプログラミング言語です。
- コンパイラ言語であり、コンパイル結果はJavaバイトコードとなり、JVM上で実行可能です。
This file contains 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
case class Cart | |
(id: CartId, | |
status: StatusType.Value, | |
customerId: CustomerId, | |
cartItems: List[CartItem]) | |
extends Entity[CartId] |
This file contains 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
case class Cart | |
(id: CartId, | |
status: StatusType.Value, | |
customerId: CustomerId, | |
cartItems: List[CartItem]) extends Entity[CartId] { | |
// ... | |
def addCartItem(cartItem: CartItem): Cart = { | |
require(cartItem.quantity > 0) | |
cartItems.find(_.itemId == cartItem.itemId).map { | |
currentItem => |
This file contains 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
protected def convertToEntity(json: J): E | |
protected def convertToEntityWithoutId(json: J): E | |
protected def createAction(implicit tjs: Writes[E], rds: Reads[J], ctx: EntityIOContext) = Action { | |
request => | |
request.body.asJson.map { | |
json => | |
json.validate[J].fold(defaultErrorHandler, { | |
validatedJson => |
- 通常変数
- 変数の値の再代入が可能。
- final
- 変数の値の再代入が禁止。
- finalフィールドはコンストラクタが完了した時点で複数のスレッドから可視となる。
- volatile
可視性のみを保証する(ロックを獲得しない)。- コスト: 読み込みはNormalと同程度で、書き込みはNormalより高い(メモリバリアのため)
- 可視性: ○
- スレッド内での共有変数への書き込みを、ほかのスレッドにも反映させる必要がある場合に利用する。
This file contains 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
case class Cart | |
(id: CartId, | |
status: StatusType.Value, | |
customerId: CustomerId, | |
cartItems: List[CartItem], | |
version: Option[Long]) extends Entity[CartId] { | |
def customer(implicit cr: CustomerRepository, | |
ctx: EntityIOContext): Try[Customer] = | |
cr.resolveById(customerId) |
This file contains 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
object Server extends App { | |
val service = new Service[HttpRequest, HttpResponse] { | |
def apply(req: HttpRequest): Future[HttpResponse] = | |
Future.value( | |
new DefaultHttpResponse( | |
req.getProtocolVersion, HttpResponseStatus.OK | |
) | |
) | |
} | |
val server = Http.serve(":8080", service) |
This file contains 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
#!/bin/sh | |
BACKUPS_DIR=~/backups | |
grep "\[インストール\]" /var/log/aptitude > $BACKUPS_DIR/apt-package.list | |
cd / | |
sudo tar zcvf $BACKUPS_DIR/etc_fail2ban.tgz etc/fail2ban | |
sudo tar zcvf $BACKUPS_DIR/etc_logwatch.tgz etc/logwatch |
This file contains 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 akka.actor._ | |
import akka.io.IO | |
import spray.can.Http | |
import spray.routing.{Directives, HttpService, RequestContext, Route} | |
trait Action { | |
def apply(request: RequestContext): Unit | |
} |
This file contains 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
// あらゆる型を加算できる型クラス Adder | |
trait Adder[A] { | |
def add(a: A, b: A): A | |
} | |
// 型クラスのインスタンス Int用 | |
implicit val intAdder = new Adder[Int] { | |
override def add(a: Int, b: Int): Int = a + b | |
} |
OlderNewer