mirror of
https://github.com/aNNiMON/Own-Programming-Language-Tutorial.git
synced 2024-09-20 00:34:20 +03:00
[functional] Deny varargs input argument for stream
This commit is contained in:
parent
2de94d94d5
commit
d643f596a8
@ -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");
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user