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 scalaz._ | |
import Scalaz._ | |
import simulacrum._ | |
import stalactite._ | |
import scala.concurrent.Future | |
import scala.io.StdIn.readLine | |
object Main { | |
trait Terminal[C[_]] { |
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 scalaz._ | |
import Scalaz._ | |
import simulacrum._ | |
import stalactite._ | |
import scala.concurrent.Future | |
class Main { | |
trait Terminal[C[_]] { | |
def read: C[String] |
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
abstract class Element(text: String) { | |
def accept(visitor: Element => Unit): Unit = | |
visitor(this) | |
} | |
case class Title(text: String) extends Element(text) | |
case class Text(text: String) extends Element(text) | |
case class Hyperlink(text: String, val url: String) extends Element(text) |
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
trait Visitor { | |
def visit(title: Title) | |
def visit(text: Text) | |
def visit(hyperlink: Hyperlink) | |
} | |
abstract class Element(val text: String) { | |
def accept(visitor: Visitor) | |
} |
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
/** | |
* This class Generates prime numbers up to a user specified | |
* maximum. The algorithm used is the Sieve of Eratosthenes. | |
* <p> | |
* Eratosthenes of Cyrene, b. c. 276 BC, Cyrene, Libya -- | |
* d. c. 194, Alexandria. The first man to calculate the | |
* circumference of the Earth. Also known for working on | |
* calendars with leap years and ran the library at Alexandria. | |
* <p> | |
* The algorithm is quite simple. Given an array of integers |
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 class Address { | |
private final String addressLine; // never null | |
private final String city; // never null | |
private final String postcode; // optional, thus may be null | |
// constructor ensures non-null fields really are non-null | |
// optional field can just be stored directly, as null means optional | |
public Address(String addressLine, String city, String postcode) { | |
this.addressLine = Preconditions.chckNotNull(addressLine); |
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.jooq.lambda.tuple.Tuple2; | |
import static java.util.stream.Stream.iterate; | |
import static org.jooq.lambda.tuple.Tuple.tuple; | |
public class Main | |
{ | |
public static void main(String[] args) | |
{ | |
iterate( |
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
package test; | |
import java.io.File; | |
import java.io.FileNotFoundException; | |
import java.io.FileReader; | |
import java.io.FileWriter; | |
import java.io.IOException; | |
import java.io.LineNumberReader; | |
import java.util.Collections; | |
import java.util.Iterator; |
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
(defmulti area | |
"Calculate the area of a shape" | |
:type) | |
(defmethod area :rectangle [shape] | |
(* (:length shape) (:width shape))) | |
(defmethod area :circle [shape] | |
(* (. Math PI) (:radius shape) (:radius shape))) |
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
IntStream.of(1, 2, 3).forEach( new IntConsumer() { public void accept(int value) { System.out.println(value); } } ); | |
IntStream.of(1, 2, 3).forEach( new IntConsumer() { public void accept(int n) { System.out.println(n); } } ); | |
IntStream.of(1, 2, 3).forEach( (int n) -> { System.out.println(n); } ); | |
IntStream.of(1, 2, 3).forEach( (int n) -> System.out.println(n) ); | |
IntStream.of(1, 2, 3).forEach( n -> System.out.println(n) ); | |
IntStream.of(1, 2, 3).forEach( System.out::println ); |