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
package sample.domain.model | |
import java.io.{ ByteArrayOutputStream, ObjectOutputStream } | |
import java.util.concurrent.TimeUnit | |
import sample.infrastructure.ulid.ULID | |
import com.google.common.cache.{ CacheBuilder, RemovalListener, RemovalNotification } | |
import org.scalatest.freespec.AnyFreeSpec | |
class MessageMetasSpec extends AnyFreeSpec { |
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
// classic | |
class Ping() extends Actor { | |
def becomOpen(becameReceive: Receive): Unit = { | |
// 今のActorにメッセージを送ることができる | |
context.become(becameReceive) | |
// 変わった後のActorにメッセージを送ることができる | |
} | |
} |
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
function openOauthAuth() { | |
const text = _getOauthAuthText(); | |
_openDialog(text); | |
} | |
function getOauthToken() { | |
const sheet = SpreadsheetApp.getActiveSheet(); | |
const code = sheet.getRange(1,2).getValue(); | |
const tokenJson = _getOauthToken(code); | |
sheet.getRange(1,4).setValue(tokenJson['access_token']); |
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 scala.collection.immutable.TreeMap | |
import scala.io.Source | |
object Main extends App { | |
val file = Source.fromFile("./hoge.txt", "utf-8") | |
val lines = file.getLines | |
val dateTimeSep = """- (\d\d\d\d)年(\d\d)月(\d\d)日 .曜日 (\d\d:\d\d)""".r |
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
trait Event[Aggregate] { | |
def applyTo(aggregate: Aggregate): Aggregate | |
} | |
trait Customer { | |
val id: String | |
val version: Long | |
def lockForAccountOverdraft(comment: String): Customer = ??? | |
def locked: Customer | |
val changes: Seq[Event[Customer]] = ??? |
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
def readAsByteArray(in: InputStream): Array[Byte] = | |
Stream.continually(in.read).takeWhile(_ != -1).map(_.toByte).toArray |
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
def swap[L, R](a: Option[Either[L, R]]): Either[L, Option[R]] = | |
(for { | |
b <- a | |
} yield for { | |
c <- b.right | |
} yield Option(c)).getOrElse(Right(None)) |
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
def splitEither[A,B](el: Seq[Either[A,B]]): (Seq[A], Seq[B]) = { | |
val (lefts, rights) = el.partition(_.isLeft) | |
(lefts.map(_.left.get), rights.map(_.right.get)) | |
} |
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
def sequence[A, B](s: Seq[Either[A, B]]): Either[A, Seq[B]] = | |
s.foldRight(Right(Nil): Either[A, List[B]]) { | |
(e, acc) => for (xs <- acc.right; x <- e.right) yield x :: xs | |
} | |
def sequence[A, B](s: Seq[Either[A, B]]): Either[A, Seq[B]] = | |
s.foldLeft(Right(Seq.empty[B]): Either[A, Seq[B]]) { (acc, e) => | |
for (xs <- acc; x <- e) yield xs :+ x | |
} |
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
def sequence[T](xs : Seq[Try[T]]) : Try[Seq[T]] = (Try(Seq[T]()) /: xs) { | |
(a, b) => a flatMap (c => b map (d => c :+ d)) | |
} |