Skip to content

Instantly share code, notes, and snippets.

View zarinfam's full-sized avatar

Saeed Zarinfam zarinfam

View GitHub Profile
@zarinfam
zarinfam / actor.scala
Last active November 16, 2017 17:21
IntelliJ IDEA Live Template for an Akka actor
import akka.actor.{ Actor, Props }
class $NAME$ extends Actor {
override def receive = ???
}
object $NAME$ {
def props: Props = Props(new $NAME$)
}
@zarinfam
zarinfam / Main.java
Created August 16, 2018 06:24
How Java 8 killed the Strategy Pattern
public class Main {
@FunctionalInterface
interface Function3 <A, B, C, R> {
public R apply (A a, B b, C c);
}
public static void main(String[] args) {
BiFunction<Integer, Integer, Integer> add = Math::addExact;
BiFunction<Integer, Integer, Integer> subtract = Math::subtractExact;
@zarinfam
zarinfam / gist.java
Created June 25, 2019 07:58
Created with Copy to Gist
interface Empty<A> {
A empty();
}
@zarinfam
zarinfam / gist.java
Created June 25, 2019 07:59
Created with Copy to Gist
class EmptyInt implements Empty<Integer>{
@Override
public Integer empty() {
return 0;
}
}
@zarinfam
zarinfam / gist.java
Created June 25, 2019 08:03
Created with Copy to Gist
interface Empty<A> {
A empty();
static Empty<Integer> emptyInt(){
return new EmptyInt();
}
}
@zarinfam
zarinfam / gist.java
Created June 25, 2019 08:07
Created with Copy to Gist
interface Empty<A> {
A empty();
static Empty<Integer> emptyInt(){
return () -> 0;
}
}
@zarinfam
zarinfam / gist.java
Created June 25, 2019 08:09
Created with Copy to Gist
final class Functions {
static <T> Tuple2<T, T> twoEmpties(Empty<T> empty) {
return Tuple.of(empty.empty(), empty.empty());
}
...
}
@zarinfam
zarinfam / gist.java
Created June 25, 2019 08:11
Created with Copy to Gist
var xAndY = twoEmpties(emptyInt());
System.out.println("{" + xAndY._1() + ", " + xAndY._2() + "}");
@zarinfam
zarinfam / gist.scala
Created June 25, 2019 08:13
Created with Copy to Gist
val xAndY = twoEmpties()
@zarinfam
zarinfam / gist.java
Created June 25, 2019 08:15
Created with Copy to Gist
interface Show<A> {
String show(A a);
static <X, Y> Show<Tuple2<X, Y>> showTuple() {
return t -> "{" + t._1() + ", " + t._2() + "}";
}
}