MCPcopy Create free account
hub / github.com/cel-expr/cel-go / optMapExpander

Function optMapExpander

parser/parser_test.go:3862–3888  ·  view source on GitHub ↗
(meh ExprHelper, target ast.Expr, args []ast.Expr)

Source from the content-addressed store, hash-verified

3860var optMapMacro = NewReceiverMacro("optMap", 2, optMapExpander)
3861
3862func optMapExpander(meh ExprHelper, target ast.Expr, args []ast.Expr) (ast.Expr, *common.Error) {
3863 varIdent := args[0]
3864 varName := ""
3865 switch varIdent.Kind() {
3866 case ast.IdentKind:
3867 varName = varIdent.AsIdent()
3868 default:
3869 return nil, meh.NewError(varIdent.ID(), "optMap() variable name must be a simple identifier")
3870 }
3871 mapExpr := args[1]
3872 return meh.NewCall(
3873 operators.Conditional,
3874 meh.NewMemberCall("hasValue", target),
3875 meh.NewCall("optional.of",
3876 meh.NewComprehension(
3877 meh.NewList(),
3878 "#unused",
3879 varName,
3880 meh.NewMemberCall("value", meh.Copy(target)),
3881 meh.NewLiteral(types.False),
3882 meh.NewIdent(varName),
3883 mapExpr,
3884 ),
3885 ),
3886 meh.NewCall("optional.none"),
3887 ), nil
3888}
3889
3890func newBenchmarkCategoryParser(tb testing.TB, options ...Option) *Parser {
3891 tb.Helper()

Callers

nothing calls this directly

Calls 11

KindMethod · 0.65
AsIdentMethod · 0.65
NewErrorMethod · 0.65
IDMethod · 0.65
NewCallMethod · 0.65
NewMemberCallMethod · 0.65
NewComprehensionMethod · 0.65
NewListMethod · 0.65
CopyMethod · 0.65
NewLiteralMethod · 0.65
NewIdentMethod · 0.65

Tested by

no test coverage detected