Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,34 @@ public RegoObject unionN(EvaluationContext ctx, RegoValue[] args) {
}

@OpaBuiltin(
name = "object.keys",
description = "Returns a set of keys in the supplied object.",
name = "object.union",
description =
"Creates a new object of the asymmetric union of two objects. For example: "
+ "`object.union({\"a\": 1}, {\"b\": 2})` results in `{\"a\": 1, \"b\": 2}`. "
+ "If both objects have the same key and both values are objects, the values are "
+ "merged recursively. Otherwise, the value in the right-hand object `b` wins.",
categories = {"objects"},
args = {
@OpaType(
type = "object",
name = "object",
description = "object to get keys from",
name = "a",
description = "left-hand object",
dynamic = @OpaDynamic(keyType = "any", valueType = "any")),
@OpaType(
type = "object",
name = "b",
description = "right-hand object",
dynamic = @OpaDynamic(keyType = "any", valueType = "any"))
},
result =
@OpaType(
type = "set",
description = "set of keys in `object`",
dynamic = @OpaDynamic(type = "any")))
type = "object",
name = "output",
dynamic = @OpaDynamic(keyType = "any", valueType = "any"),
description =
"a new object which is the result of an asymmetric recursive union of two "
+ "objects where conflicts are resolved by choosing the key from the "
+ "right-hand object `b`"))
public RegoObject union(EvaluationContext ctx, RegoValue[] args) {
if (!(args[0] instanceof RegoObject)) {
throw new TypeError("object.union: operand 1 must be object but got " + args[0].getTypeName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,25 @@ public static Map<String, BiFunction<EvaluationContext, RegoValue[], RegoValue>>
"union", instance::union);
}

@OpaBuiltin(
name = "union",
description = "Returns the union of the given input sets.",
categories = {"sets"},
args = {
@OpaType(
type = "set",
name = "xs",
description = "set of sets to merge",
dynamic = @OpaDynamic(type = "set"))
},
result =
@OpaType(
type = "set",
name = "y",
description = "the union of all `xs` sets",
dynamic = @OpaDynamic(type = "any")))
public RegoSet union(EvaluationContext ctx, RegoValue[] args) {
RegoSet xs = (RegoSet) args[0];
RegoSet xs = getArg(args, 0, RegoSet.class);

Set<RegoValue> y =
xs.getValue().stream()
Expand Down
Loading