Skip to content

Instantly share code, notes, and snippets.

public static void main(String... args) {
int count = 0;
for (int i = 0; i<100000; i++) {
count += doubleMe(2);
count += doubleMe(4);
}
System.out.println(count);
}
public static void main(String... args) {
int count = 0;
for (int i = 0; i<100000; i++) {
count += wrapper();
}
System.out.println(count);
}
private static int wrapper() {
for {
p <- people
if p.age < 30 && p.age >= 20
} yield p.name
SELECT name FROM people WHERE age < 30 AND age >= 20
people.withFilter(p => p.age < 30 && p.age >= 20).map(p => p.name)
import scala.util.Random
object MonthHall extends App {
val numberOfIterations = 1000000
val numberOfWins = (0 until numberOfIterations).count(_ => {
val winningDoor = Random.nextInt(3)
val chosenDoor = Random.nextInt(3)
@polyglotpiglet
polyglotpiglet / NoVisibility.java
Created November 18, 2017 11:56
NoVisibility thread example
import java.util.Random;
import java.util.concurrent.*;
class NoVisibility {
private boolean ready;
private int number;
private final ExecutorService executor;
private final Random random;
import org.junit.Test;
import java.util.Random;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import static org.assertj.core.api.Assertions.assertThat;
public class NoVisibilityTest {
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] {}
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] {}