中身はともかく、ストーリーを忘れないようにメモ
純粋関数型言語でデータ構造を書くと以下のような利点が得られて嬉しい
- 自動的に永続性(persistent)が得られる。(要素を更新した後でも、更新前のデータに安全にアクセス可能)
- 破壊的代入を伴う命令形言語で実装された多くのデータ構造は短命(ephemeral)である。
- 命令形言語では複雑になる、ある主のデータ構造が抽象化を通して非常にシンプルになる(LinkedList, Red-Black Tree)
| #!/bin/bash | |
| CONF_PATH="$HOME/.config/gol/links" | |
| # _gol_record key | |
| _gol_record() { | |
| key="$1" | |
| if [ -n "$key" ]; then | |
| grep "$key " "$CONF_PATH" |
| case class Foo(value: Int) | |
| case class Bar(value: String) | |
| case class Baz(private val foo: Foo, private val bar: Bar) { | |
| def fooBar: String = foo.value.toString + bar.value | |
| } | |
| val baz = Baz(Foo(1), Bar("bar")) | |
| scala> Baz.unapply | |
| case def unapply(x$0: Baz): Option[(Foo, Bar)] |
| import com.twitter.util.Future | |
| import scala.reflect.ClassTag | |
| // generated code | |
| case class FooReqThrift(value: Int) | |
| case class ThriftException(message: String, cause: Throwable) extends RuntimeException(message, cause) | |
| // libs | |
| abstract class RequestAdapter[ReqThrift, ReqDto] { | |
| def adapt(a: ReqThrift): Future[ReqDto] |
| # basically from http://qiita.com/masa0x80/items/346b4b9c0ff08205995e | |
| function __insert_abbreviation | |
| commandline | read -l buffer | |
| switch (string trim -r $buffer | string split ' ')[-1] | |
| case G | |
| string replace "G" "| grep" $buffer | read replaced | |
| case X | |
| string replace "X" "| xargs -I {}" $buffer | read replaced | |
| case H |
| # coursierをon | |
| function coursier_enable() { | |
| sed -i 's/\/\/\(addSbtPlugin("io.get-coursier" % "sbt-coursier" % ".*")\)/\1/' ~/.sbt/0.13/plugins/global.sbt | |
| } | |
| # coursierをoff | |
| function coursier_disable() { | |
| sed -i '/^addSbtPlugin("io.get-coursier" % "sbt-coursier" % ".*")/s/^/\/\//' ~/.sbt/0.13/plugins/global.sbt | |
| } |
| abstract class DomainException(message: String, cause: Throwable) extends RuntimeException(message, cause) | |
| sealed abstract class FooDomainException(message: String, cause: Throwable) extends DomainException(message, cause) | |
| // causeが必ず存在するような例外 | |
| case class BarDomainException(message: String, cause: Throwable) extends FooDomainException(message, cause) | |
| // causeがあったりなかったりするような例外 | |
| case class BazDomainException(message: String, cause: Throwable = null) extends FooDomainException(message, cause) |
| // \r\n a ==> ok | |
| // \u000D\u000A b ==> compile error |
| package scalaworld.macros | |
| package com.folio.account.macros | |
| import scala.collection.immutable.Seq | |
| import scala.meta._ | |
| /** | |
| * annotation for case class. | |
| * |