Skip to content

Instantly share code, notes, and snippets.

View yasuabe's full-sized avatar

Yasuyuki Abe yasuabe

View GitHub Profile
@yasuabe
yasuabe / accountability.sc
Created March 26, 2018 18:35
analysis patterns knowledge level implemented in type level programming
import shapeless.ops.coproduct.{IsCCons, Selector, Unifier}
import shapeless.{:+:, CNil, Coproduct}
// Party Types -------------------------
sealed trait PartyType
sealed trait Region extends PartyType
sealed trait Division extends PartyType
sealed trait Doctor extends PartyType
@yasuabe
yasuabe / sized_vector_matrix.sc
Last active January 18, 2019 08:12
implement vector and matrix with Shapeless's Sized
import shapeless.Nat._
import shapeless.ops.nat.ToInt
import shapeless.syntax.sized._
import shapeless.{Nat, Sized}
type Vect[N <: Nat] = Sized[IndexedSeq[Int], N]
def vect = Sized.apply[IndexedSeq]
def times[L <: Nat](k: Int, v1: Vect[L]): Vect[L] = v1.map(_ * k)
import shapeless.ops.hlist.{Length, Repeat}
import shapeless.{::, Generic, HList, HNil, Nat}
case class IceCream(name: String, numCherries: Int, inCone: Boolean)
def repeat[I <: HList, L <: Nat, O <: HList](in: I, s: String)(
implicit
len: Length.Aux[I, L],
rep: Repeat.Aux[String :: HNil, L, O]
): O = rep(s :: HNil)
import cats.MonoidK
import scala.util.Try
import cats.data.Kleisli
import cats.syntax.option._
import cats.syntax.either._
import cats.syntax.compose._
import cats.syntax.foldable._
import cats.syntax.arrow._
import cats.syntax.arrowChoice._
package type_classes.partialorder
import cats.PartialOrder
import cats.syntax.partialOrder._
import cats.instances.AllInstances
import cats.kernel.BoundedSemilattice
import cats.kernel.laws.discipline.{BoundedSemilatticeTests, PartialOrderTests}
import org.scalacheck.{Arbitrary, Gen}
import org.specs2.Specification
import org.typelevel.discipline.specs2.Discipline
import java.time.LocalDate
import java.time.temporal.ChronoUnit.{DAYS, MONTHS}
import cats.instances.AllInstances
import cats.kernel.laws.discipline.PartialOrderTests
import cats.{Foldable, Monad, Monoid, PartialOrder}
import eu.timepit.refined.api.Refined
import eu.timepit.refined.numeric.Positive
import eu.timepit.refined.refineV
import org.scalacheck.{Arbitrary, Gen}
import cats.data.{Kleisli, Nested, Tuple2K}
import cats.implicits._
import cats.{Distributive, Functor, Id, Traverse, ~>}
// def distribute[G[_]: Functor, A, B](ga: G[A])(f: A => F[B]): F[G[B]]
// def cosequence[G[_]: Functor, A](ga: G[F[A]]): F[G[A]] = distribute(ga)(identity)
// Function0 ------------------------------
// F = () => ?
val d0 = Distributive[() => ?]
import cats.data.{Kleisli, Nested, Tuple2K}
import cats.implicits._
import cats.{Distributive, Functor, Id, Traverse, ~>}
// def distribute[G[_]: Functor, A, B](ga: G[A])(f: A => F[B]): F[G[B]]
// def cosequence[G[_]: Functor, A](ga: G[F[A]]): F[G[A]] = distribute(ga)(identity)
// Function0 ------------------------------
// F = () => ?
val d0 = Distributive[() => ?]
val afb0: Char => () => String = c => () => s"<$c>"
val ga0 = List('a', 'b')
package qiita
import java.util.concurrent.{ExecutorService, Executors}
import cats.effect._
import cats.syntax.functor._
import fs2.{Pipe, Stream, io, text}
import scala.concurrent.ExecutionContext
import scala.util.Try