MCPcopy Create free account
hub / github.com/cel-expr/cel-cpp / MinList

Function MinList

extensions/math_ext.cc:98–126  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

96}
97
98absl::StatusOr<Value> MinList(
99 const ListValue& values,
100 const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool,
101 google::protobuf::MessageFactory* absl_nonnull message_factory,
102 google::protobuf::Arena* absl_nonnull arena) {
103 CEL_ASSIGN_OR_RETURN(auto iterator, values.NewIterator());
104 if (!iterator->HasNext()) {
105 return ErrorValue(
106 absl::InvalidArgumentError("math.@min argument must not be empty"));
107 }
108 Value value;
109 CEL_RETURN_IF_ERROR(
110 iterator->Next(descriptor_pool, message_factory, arena, &value));
111 absl::StatusOr<CelNumber> current = ValueToNumber(value, kMathMin);
112 if (!current.ok()) {
113 return ErrorValue{current.status()};
114 }
115 CelNumber min = *current;
116 while (iterator->HasNext()) {
117 CEL_RETURN_IF_ERROR(
118 iterator->Next(descriptor_pool, message_factory, arena, &value));
119 absl::StatusOr<CelNumber> other = ValueToNumber(value, kMathMin);
120 if (!other.ok()) {
121 return ErrorValue{other.status()};
122 }
123 min = MinNumber(min, *other);
124 }
125 return NumberToValue(min);
126}
127
128CelNumber MaxNumber(CelNumber v1, CelNumber v2) {
129 if (v2 > v1) {

Callers

nothing calls this directly

Calls 7

ErrorValueFunction · 0.85
ValueToNumberFunction · 0.85
MinNumberFunction · 0.85
NumberToValueFunction · 0.85
HasNextMethod · 0.45
NextMethod · 0.45
okMethod · 0.45

Tested by

no test coverage detected