Skip to content

Instantly share code, notes, and snippets.

View ghik's full-sized avatar

Roman Janusz ghik

View GitHub Profile
import scala.language.higherKinds
sealed abstract class Stuff[F[_], +A]
case class Suspend[F[_], A](a: () => F[A])
extends Stuff[F, A]
def extract[F[_], A](source: Stuff[F, A]): Suspend[F, A] =
source match {
case ref @ Suspend(_) => ref.asInstanceOf[Suspend[F,A]]
import java.lang.reflect.{GenericArrayType, Modifier, ParameterizedType, Type, TypeVariable, WildcardType}
import scala.reflect.{ClassTag, classTag}
object StaticForwarderGenerator {
implicit class arrayOps[A](private val array: Array[A]) extends AnyVal {
def mkStringOrEmpty(start: String, sep: String, end: String): String =
if (array.isEmpty) "" else array.mkString(start, sep, end)
}
def generateFor[T: ClassTag]: String = {
@ghik
ghik / BoundsChecking.scala
Last active August 30, 2021 12:20
Benchmarks for explicit list bounds checking vs relying on exceptions
import org.openjdk.jmh.annotations._
final class NoStackTraceIndexOutOfBoundsException extends IndexOutOfBoundsException {
override def fillInStackTrace(): Throwable = this
}
final class NoStackTraceArraySeq[+T](values: Array[T]) {
val size: Int = values.length
def apply(idx: Int): T =
@ghik
ghik / TaglessFinalFantasy.scala
Created September 28, 2021 09:56
Tagless Final na kolanie
import cats._
import cats.effect.IO
import cats.implicits._
case class UserId(value: String) extends AnyVal
case class User(id: UserId, name: String, age: Int)
trait DbApi[F[_]] {
def load(id: UserId): F[Option[User]]
def save(user: User): F[Unit]