Skip to content

Instantly share code, notes, and snippets.

@jooohn
jooohn / FizzBuzz.scala
Created Jul 20, 2019
Compile time FizzBuzz in Dotty
View FizzBuzz.scala
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 Jun 12, 2019
Fibo implementation with Dotty
View DottyFibo.scala
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 Dec 10, 2018
implicit FizzBuzz
View FizzBuzz.scala
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]
View example.scala
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)
@jooohn
jooohn / file0.txt
Last active Aug 29, 2015
ノンブロッキングな特性のメモ ref: http://qiita.com/jooohn1234/items/7be62da14a2d088181fd
View file0.txt
やったらすぐ終わるんだけど、優先度が高いタスクがすごい勢いで入ってきて、一向に終わらないというか始まらない。
View gist:6992726
// getSingletonInstance は static メソッドになる?
class Module
{
use TSingleton;
static $FUNC_NAME_SINGLETON = 'singleton';
static function singleton()
{