This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| for { | |
| p <- people | |
| if p.age < 30 && p.age >= 20 | |
| } yield p.name |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SELECT name FROM people WHERE age < 30 AND age >= 20 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| people.withFilter(p => p.age < 30 && p.age >= 20).map(p => p.name) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.Random; | |
| import java.util.concurrent.*; | |
| class NoVisibility { | |
| private boolean ready; | |
| private int number; | |
| private final ExecutorService executor; | |
| private final Random random; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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] {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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] {} |