-
Notifications
You must be signed in to change notification settings - Fork 0
/
Zambda.java
54 lines (47 loc) · 1.22 KB
/
Zambda.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
package frc.libzodiac;
import edu.wpi.first.wpilibj2.command.Subsystem;
/**
* Allow you to construct <i>WPILib</i>'s <code>Command</code> with a lambda.
*/
public final class Zambda extends ZCommand {
/**
* The action to perform.
*/
private final Runnable exec;
/**
* Create a command from code with specified requirement(s).
*
* @param req requirement of this command
* @param exec the code to execute
*/
public Zambda(Subsystem req, Runnable exec) {
this.exec = exec;
this.require(req);
}
/**
* Create a command from code with specified requirement(s).
*
* @param req requirement of this command
* @param exec the code to execute
*/
public Zambda(Subsystem[] req, Runnable exec) {
this.exec = exec;
for (final var i : req) {
this.require(i);
}
}
/**
* Create an independant/no requirement command.
*
* @param exec the code to execute
* @return a new command
*/
public static Zambda indep(Runnable exec) {
return new Zambda(new Subsystem[]{}, exec);
}
@Override
protected ZCommand exec() {
this.exec.run();
return this;
}
}