Skip to content

Instantly share code, notes, and snippets.

@jooohn
jooohn / FizzBuzz.scala
Created July 20, 2019 14:25
Compile time FizzBuzz in Dotty
import scala.compiletime._
object Main {
type -[A <: Int, B <: Int] <: Int = B match {
case 0 => A
case S[b] => A match {
case S[a] => a - b
case _ => Nothing
}
@jooohn
jooohn / DottyFibo.scala
Last active June 12, 2019 15:37
Fibo implementation with Dotty
object Main {
trait Monad[F[_]] {
def pure[A](a: A): F[A]
def map[A, B](fa: F[A])(f: A => B): F[B] = flatMap(fa)(f andThen pure)
def flatMap[A, B](fa: F[A])(f: A => F[B]): F[B]
}
def (fa: F[A]) map[F[_], A, B](f: A => B) given Monad[F]: F[B] = the[Monad[F]].map(fa)(f)
def (fa: F[A]) flatMap[F[_], A, B](f: A => F[B]) given Monad[F]: F[B] = the[Monad[F]].flatMap(fa)(f)
@jooohn
jooohn / FizzBuzz.scala
Last active December 10, 2018 21:10
implicit FizzBuzz
sealed trait Nat
trait Zero extends Nat
trait Succ[N <: Nat] extends Nat
type Nat1 = Succ[Zero]
type Nat2 = Succ[Nat1]
type Nat3 = Succ[Nat2]
type Nat4 = Succ[Nat3]
type Nat5 = Succ[Nat4]
type ActionCont[T] = EitherT[Future, UseCaseResult, A]
final class FindWarriorImpl[Ctx <: IOContext](
ctx: Ctx,
repository: WarriorRepository[Future]
) extends FindWarrior {
def apply(id: WarriorId): ActionCont[Warrior] = EitherT {
repository.resolveBy(id) map {
case Some(w) => Right(w)
case None => Left(WarriorNotFound)
// getSingletonInstance は static メソッドになる?
class Module
{
use TSingleton;
static $FUNC_NAME_SINGLETON = 'singleton';
static function singleton()
{
@jooohn
jooohn / file0.txt
Last active August 29, 2015 14:21
ノンブロッキングな特性のメモ ref: http://qiita.com/jooohn1234/items/7be62da14a2d088181fd
やったらすぐ終わるんだけど、優先度が高いタスクがすごい勢いで入ってきて、一向に終わらないというか始まらない。