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

Method combine

policy/composer.go:475–503  ·  view source on GitHub ↗

combine assembles a new compositionStep from the target output step an an input output step. non-optional.combine(non-optional) // non-optional (non-optional && conditional).combine(optional) // optional (non-optional && unconditional).combine(optional) // non-optional The last combination case is

(step compositionStep)

Source from the content-addressed store, hash-verified

473// The last combination case is unusual, but effectively it means that the non-optional value prunes away
474// the potential optional output.
475func (s nonOptionalCompositionStep) combine(step compositionStep) compositionStep {
476 if step == nil {
477 // The input `step` may be nil if this is the first compositionStep
478 return s
479 }
480 ctx := s.ctx
481 trueCondition := ctx.NewLiteral(types.True)
482 if step.isOptional() {
483 // If the step is optional, convert the non-optional value to an optional one and return a ternary
484 if s.isConditional() {
485 return newOptionalCompositionStep(ctx,
486 trueCondition,
487 ctx.NewCall(operators.Conditional,
488 s.condition(),
489 ctx.NewCall("optional.of", s.expr()),
490 step.expr()),
491 )
492 }
493 // The `step` is pruned away by a unconditional non-optional step `s`.
494 // Likely a candidate for dead-code warnings.
495 return s
496 }
497 return newNonOptionalCompositionStep(ctx,
498 trueCondition,
499 ctx.NewCall(operators.Conditional,
500 s.condition(),
501 s.expr(),
502 step.expr()))
503}
504
505// newOptionalCompositionStep returns an output step with an optional policy output.
506func newOptionalCompositionStep(ctx *cel.OptimizerContext, cond, out ast.Expr) optionalCompositionStep {

Callers

nothing calls this directly

Calls 8

NewLiteralMethod · 0.65
isOptionalMethod · 0.65
isConditionalMethod · 0.65
NewCallMethod · 0.65
conditionMethod · 0.65
exprMethod · 0.65

Tested by

no test coverage detected