Skip to content

Instantly share code, notes, and snippets.

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 {
// classic
class Ping() extends Actor {
def becomOpen(becameReceive: Receive): Unit = {
// 今のActorにメッセージを送ることができる
context.become(becameReceive)
// 変わった後のActorにメッセージを送ることができる
}
}
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']);
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
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]] = ???
def readAsByteArray(in: InputStream): Array[Byte] =
Stream.continually(in.read).takeWhile(_ != -1).map(_.toByte).toArray
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))
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))
}
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
}
def sequence[T](xs : Seq[Try[T]]) : Try[Seq[T]] = (Try(Seq[T]()) /: xs) {
(a, b) => a flatMap (c => b map (d => c :+ d))
}