Skip to content

Commit 42391da

Browse files
committed
Add some functional items
Closes jagrosh#8
1 parent f4274e7 commit 42391da

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

src/main/java/com/jagrosh/jagtag/libraries/Functional.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,30 @@ public static Collection<Method> getMethods() {
6666
return in[2];
6767
}, "|then:", "|else:"),
6868

69+
// performs a conditional and outputs true/false
70+
new Method("bool", (env, in) -> {
71+
if(in[0].equalsIgnoreCase("true"))
72+
return "true";
73+
if(in[0].equalsIgnoreCase("false"))
74+
return "false";
75+
return Boolean.toString(evaluateStatement(in[0]));
76+
}),
77+
78+
// performs a switch conditional
79+
new Method("switch", (env,in) -> {
80+
String[] cases = in[1].split("\\|");
81+
82+
if(cases.length % 2 != 0)
83+
return in[in.length - 1];
84+
85+
for (int i = 0; i < cases.length; i += 2) {
86+
if(in[0].equals(cases[i]))
87+
return cases[i + 1];
88+
}
89+
90+
return in[in.length - 1];
91+
}, "|cases:", "|default:"),
92+
6993
// performs basic mathematical function
7094
new Method("math", (env, in) -> {
7195
return evaluateMath(in[0]);

0 commit comments

Comments
 (0)