以下のような要件をモデリングするには?
- ディスク情報は製造者、サイズを持つ。
- 製造者はディスクを製造したメーカーの識別子を表す。
- サイズはディスクのサイズをGB単位で表す。
- ディスク情報は、さらにディスクの種類に応じた情報を持つ
- ディスクの種類がハードディスクの場合、回転数(RPM)、プラッタの数を持つ
- ディスクの種類が*マルチメディアカード(MMC)*の場合、ピンの数
package jkugiya.fp.eff | |
import org.atnos.eff.concurrent.Scheduler | |
import scala.concurrent.{ ExecutionContext, Future } | |
object Usage { | |
import cats._ | |
import org.atnos.eff.future.{ _future, fromFuture } |
package jkugiya.fp.mt | |
import scala.concurrent.{ ExecutionContext, Future } | |
object Usage { | |
import cats._ | |
import data._ | |
case class Inventory( |
import scala.util.Random | |
class DomainObject( | |
val id: Option[String] | |
) { | |
protected def markNew(): Either[String, Unit] = UnitOfWork.getCurrent.registerNew(this) | |
protected def markClean(): Either[String, Unit] = UnitOfWork.getCurrent.registerClean(this) | |
protected def markDirty(): Either[String, Unit] = UnitOfWork.getCurrent.registerDirty(this) | |
protected def markRemoved(): Either[String, Unit] = UnitOfWork.getCurrent.registerRemoved(this) | |
} |
object Covariant { | |
trait Animal | |
trait Cat extends Animal { | |
def bow(): Cat | |
} | |
trait Dog extends Animal { | |
def bow(): Dog | |
} | |
class CatDog extends Cat with Dog { |
openssl s_client -starttls smtp -crlf -connect ${MAIL_HOST}:${MAIL_PORT} | |
EHLO ${MAIL_HOST} | |
AUTH PLAIN `printf "%s\0%s\0%s" ${MAIL_USER} ${MAIL_USER} ${MAIL_PASSWORD} | openssl base64 -e | tr -d '\n';echo | |
` | |
mail from: <${FROM_ADDRESS}> | |
rcpt to: <${TO_ADDRESS}> | |
data | |
From: from<${FROM_ADDRESS}> | |
To: to<${TO_ADDRESS}> |
trait UUIDTypeBinder { | |
implicit val uuidPBF: ParameterBinderFactory[UUID] = ParameterBinderFactory[UUID] { value => (stmt, idx) => | |
stmt.setObject(idx, value) | |
} | |
implicit val uuidTB: TypeBinder[UUID] = new TypeBinder[UUID] { | |
override def apply(rs: ResultSet, columnIndex: Int): UUID = rs.getObject(columnIndex, classOf[UUID]) | |
override def apply(rs: ResultSet, columnLabel: String): UUID = rs.getObject(columnLabel, classOf[UUID]) | |
} |
package exam | |
import java.util.Locale | |
object RegexExam { | |
import scala.collection.mutable | |
private val PASS1 = """([A-Z]+)([A-Z][a-z])""".r | |
private val PASS2 = """([a-z\d])([A-Z])""".r | |
private val REPLACEMENT = "$1_$2" |
def create(): String = { | |
// This is not url safe. It may cause problem in web application. | |
// val encoder = Base64.getEncoder | |
val encoder = Base64.getUrlEncoder | |
val uuid = UUID.randomUUID() | |
val buffer = ByteBuffer.wrap(new Array[Byte](16)) | |
buffer.putLong(uuid.getMostSignificantBits) | |
buffer.putLong(uuid.getLeastSignificantBits) | |
encoder.encodeToString(buffer.array()) | |
} |