-
Notifications
You must be signed in to change notification settings - Fork 0
/
Helpers.java
69 lines (57 loc) · 1.9 KB
/
Helpers.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package examples;
import org.immutables.value.Value;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.function.Function;
@Value.Style(
of = "new",
allParameters = true
)
@Value.Include({
SimpleInterpreter.M.class,
SimpleInterpreter.Term.class,
SimpleInterpreter.Con.class,
SimpleInterpreter.Add.class,
SimpleInterpreter.Lam.class,
SimpleInterpreter.App.class,
SimpleInterpreter.Num.class,
SimpleInterpreter.Fun.class,
SimpleInterpreter.Var.class,
Pair.class
})
public class Helpers {
public static <T> List<T> cons(T value, List<T> list) {
ArrayList<T> worker = new ArrayList<>();
worker.add(value);
worker.addAll(list);
return Collections.unmodifiableList(worker);
}
public static <A> SimpleInterpreter.M<A> M(A a) {
return new ImmutableM<>(a);
}
public static SimpleInterpreter.Num Num(int n) {
return new ImmutableNum(n);
}
public static SimpleInterpreter.Fun Fun(Function<SimpleInterpreter.Value, SimpleInterpreter.M<SimpleInterpreter.Value>> f) {
return new ImmutableFun(f);
}
public static <A, B> Pair<A, B> Pair(A a, B b) {
return new ImmutablePair<>(a, b);
}
public static SimpleInterpreter.App App(SimpleInterpreter.Term fun, SimpleInterpreter.Term arg) {
return new ImmutableApp(fun, arg);
}
public static SimpleInterpreter.Lam Lam(String x, SimpleInterpreter.Term body) {
return new ImmutableLam(x, body);
}
public static SimpleInterpreter.Add Add(SimpleInterpreter.Term l, SimpleInterpreter.Term r) {
return new ImmutableAdd(l, r);
}
public static SimpleInterpreter.Var Var(String x) {
return new ImmutableVar(x);
}
public static SimpleInterpreter.Con Con(int n) {
return new ImmutableCon(n);
}
}