Skip to content

Instantly share code, notes, and snippets.

object Main extends App {
/*
Contravariant: F[B] is a subtype of F[A] if A is a subtype of B
*/
trait Shape {}
case class Circle(radius: Double) extends Shape
object Main extends App {
/*
Covariant: F[B] is a subtype of F[A] if B is a subtype of A
*/
trait Shape {}
case class Circle(radius: Double) extends Shape
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
public class Main {
public interface Cat {
}
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.IntStream;
public class Main {
private static final AtomicInteger COUNTER = new AtomicInteger();
private static final int THRESHOLD = 5;
object Rawr extends App {
val namedThreadFactory: ThreadFactory = new ThreadFactoryBuilder()
.setNameFormat("meow-%d")
.build()
val es: ScheduledExecutorService = Executors.newScheduledThreadPool(1, namedThreadFactory)
def cat() = new Runnable {
override def run(): Unit = {
println(Thread.currentThread().getName)
object QuickSort {
def quickSort(arr: Array[Int]): Array[Int] = {
val copy = arr.clone()
go(copy, 0, copy.length - 1)
copy
}
private def go(a: Array[Int], l: Int, r: Int): Unit = {
if (l < r) {
/*
For naming thread pools (which I like to do so I can search my thread dumps quickly but you really don't have to)
libraryDependencies += "com.google.guava" % "guava" % "12.0"
*/
object Par {
type Par[A] = ExecutorService => Future[A]
private case class UnitFuture[A](get: A) extends Future[A] {
trait DataReader {
def readName(): String
}
trait DummyDataReader extends DataReader {
def readName(): String = "bEllA"
}
class GreeterService {
self: DataReader =>
/*
This doesnt compile because foo is expecting a type
class which takes one type parameter but Function1
takes two
*/
object DoesntCompile {
def foo[F[_], A](fa: F[A]): String = fa.toString
foo { x: Int => x * 2 }
sealed trait InMyPocket[-A]
sealed trait Cuddler
final case class Puppy(name: String) extends Cuddler
object VarianceExample {
var dog: InMyPocket[Puppy] = new InMyPocket[Puppy] {}
var cuddler: InMyPocket[Cuddler] = new InMyPocket[Cuddler] {}