[functional] Deny varargs input argument for stream

This commit is contained in:
aNNiMON 2023-10-05 16:32:18 +03:00 committed by Victor Melnik
parent 2de94d94d5
commit d643f596a8

View File

@ -9,18 +9,11 @@ public final class functional_stream implements Function {
public Value execute(Value[] args) {
Arguments.checkAtLeast(1, args.length);
if (args.length > 1) {
return new StreamValue(new ArrayValue(args));
}
final Value value = args[0];
switch (value.type()) {
case Types.MAP:
return new StreamValue(((MapValue) value).toPairs());
case Types.ARRAY:
return new StreamValue((ArrayValue) value);
default:
throw new TypeException("Invalid argument. Array or map expected");
}
return switch (value.type()) {
case Types.MAP -> new StreamValue(((MapValue) value).toPairs());
case Types.ARRAY -> new StreamValue((ArrayValue) value);
default -> throw new TypeException("Invalid argument. Array or map expected");
};
}
}