Refactor code to use ListValue.wrap(Stream)

Simplifies code (improving readability) and unifies `Stream<Value>` to `ListValue` handling
This commit is contained in:
altrisi authored and GitHub committed 2023-01-19 01:40:29 +01:00
1 parent dd1dc3756a
commit 17249c3c77
15 files changed
+66 -85

No files matched your search

@@ -112,7 +112,7 @@ public class ControlFlow {
StringValue.of(f.getString()),
NumericValue.of(f.getToken().lineno+1),
NumericValue.of(f.getToken().linepos+1)
)).collect(Collectors.toList())),
))),
StringValue.of("locals"), MapValue.wrap(ret.context.variables.entrySet().stream().filter(e -> !e.getKey().equals("_trace")).collect(Collectors.toMap(
e -> StringValue.of(e.getKey()),
@@ -17,7 +17,6 @@ import carpet.script.value.NumericValue;
import carpet.script.value.StringValue;
import carpet.script.value.Value;
import com.google.gson.JsonParseException;
import com.google.gson.JsonParser;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
@@ -186,7 +185,7 @@ public class DataStructures {
if (v instanceof MapValue)
return ListValue.wrap(((MapValue) v).getMap().entrySet().stream().map(
(p) -> ListValue.of(p.getKey(), p.getValue())
).collect(Collectors.toList()));
));
return Value.NULL;
});
@@ -18,7 +18,6 @@ import carpet.script.value.Value;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.stream.Collectors;
public class Functions {
public static void apply(Expression expression) // public just to get the javadoc right
@@ -31,10 +30,10 @@ public class Functions {
c.host.importModule(c, moduleName);
moduleName = moduleName.toLowerCase(Locale.ROOT);
if (lv.size() > 1)
c.host.importNames(c, expression.module, moduleName, lv.subList(1, lv.size()).stream().map(Value::getString).collect(Collectors.toList()));
c.host.importNames(c, expression.module, moduleName, lv.subList(1, lv.size()).stream().map(Value::getString).toList());
if (t == Context.VOID)
return Value.NULL;
return ListValue.wrap(c.host.availableImports(moduleName).map(StringValue::new).collect(Collectors.toList()));
return ListValue.wrap(c.host.availableImports(moduleName).map(StringValue::new));
});