@@ -229,6 +229,33 @@ absl::StatusOr<Value> OptionalOptIndexOptionalValue(
229229 return ErrorValue{runtime_internal::CreateNoMatchingOverloadError (" _[?_]" )};
230230}
231231
232+ absl::StatusOr<Value> ListFirst (const cel::ListValue& list,
233+ const google::protobuf::DescriptorPool* descriptor_pool,
234+ google::protobuf::MessageFactory* message_factory,
235+ google::protobuf::Arena* arena) {
236+ CEL_ASSIGN_OR_RETURN (size_t size, list.Size ());
237+ if (size == 0 ) {
238+ return Value (OptionalValue::None ());
239+ }
240+ CEL_ASSIGN_OR_RETURN (Value value,
241+ list.Get (0 , descriptor_pool, message_factory, arena));
242+ return Value (OptionalValue::Of (std::move (value), arena));
243+ }
244+
245+ absl::StatusOr<Value> ListLast (const cel::ListValue& list,
246+ const google::protobuf::DescriptorPool* descriptor_pool,
247+ google::protobuf::MessageFactory* message_factory,
248+ google::protobuf::Arena* arena) {
249+ CEL_ASSIGN_OR_RETURN (size_t size, list.Size ());
250+ if (size == 0 ) {
251+ return Value (OptionalValue::None ());
252+ }
253+ CEL_ASSIGN_OR_RETURN (Value value,
254+ list.Get (static_cast <int64_t >(size) - 1 , descriptor_pool,
255+ message_factory, arena));
256+ return Value (OptionalValue::Of (std::move (value), arena));
257+ }
258+
232259absl::StatusOr<Value> ListUnwrapOpt (
233260 const ListValue& list,
234261 const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool,
@@ -332,6 +359,16 @@ absl::Status RegisterOptionalTypeFunctions(FunctionRegistry& registry,
332359 " unwrapOpt" , true ),
333360 UnaryFunctionAdapter<absl::StatusOr<Value>, ListValue>::WrapFunction (
334361 &ListUnwrapOpt)));
362+ CEL_RETURN_IF_ERROR (registry.Register (
363+ UnaryFunctionAdapter<absl::StatusOr<Value>, ListValue>::CreateDescriptor (
364+ " first" , true ),
365+ UnaryFunctionAdapter<absl::StatusOr<Value>, ListValue>::WrapFunction (
366+ &ListFirst)));
367+ CEL_RETURN_IF_ERROR (registry.Register (
368+ UnaryFunctionAdapter<absl::StatusOr<Value>, ListValue>::CreateDescriptor (
369+ " last" , true ),
370+ UnaryFunctionAdapter<absl::StatusOr<Value>, ListValue>::WrapFunction (
371+ &ListLast)));
335372 return absl::OkStatus ();
336373}
337374
0 commit comments