Skip to content

Commit d643f59

Browse files
committed
[functional] Deny varargs input argument for stream
1 parent 2de94d9 commit d643f59

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

modules/main/src/main/java/com/annimon/ownlang/modules/functional/functional_stream.java

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,11 @@ public final class functional_stream implements Function {
99
public Value execute(Value[] args) {
1010
Arguments.checkAtLeast(1, args.length);
1111

12-
if (args.length > 1) {
13-
return new StreamValue(new ArrayValue(args));
14-
}
15-
1612
final Value value = args[0];
17-
switch (value.type()) {
18-
case Types.MAP:
19-
return new StreamValue(((MapValue) value).toPairs());
20-
case Types.ARRAY:
21-
return new StreamValue((ArrayValue) value);
22-
default:
23-
throw new TypeException("Invalid argument. Array or map expected");
24-
}
13+
return switch (value.type()) {
14+
case Types.MAP -> new StreamValue(((MapValue) value).toPairs());
15+
case Types.ARRAY -> new StreamValue((ArrayValue) value);
16+
default -> throw new TypeException("Invalid argument. Array or map expected");
17+
};
2518
}
2619
}

0 commit comments

Comments
 (0)