Debian Codegraph @

collection/coalesce.go

raw symbols SCIP
1 // Copyright IBM Corp. 2020, 2025
2 // SPDX-License-Identifier: MPL-2.0
3
4 package collectionscip-go gomod github.com/hashicorp/go-cty-funcs . `github.com/hashicorp/go-cty-funcs/collection`/
5
6 import (
7 "errorsscip-go gomod github.com/golang/go/src go1.24.0 errors/"
8
9 "github.com/zclconf/go-cty/ctyscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/"
10 "github.com/zclconf/go-cty/cty/convertscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty/convert`/"
11 "github.com/zclconf/go-cty/cty/functionscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty/function`/"
12 )
13
14 // Coalesce takes any number of arguments and returns the first one that isn't
15 // empty.
16 func Coalescescip-go gomod github.com/hashicorp/go-cty-funcs . `github.com/hashicorp/go-cty-funcs/collection`/Coalesce().(args ...ctyscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/.Valuescip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/Value#) (ctyscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/.Valuescip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/Value#, error) {
17 return CoalesceFuncscip-go gomod github.com/hashicorp/go-cty-funcs . `github.com/hashicorp/go-cty-funcs/collection`/CoalesceFunc..Callscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty/function`/Function#Call().(args)
18 }
19
20 // CoalesceFunc constructs a function that takes any number of arguments and
21 // returns the first one that isn't empty. This function was copied from go-cty
22 // stdlib and modified so that it returns the first *non-empty* non-null
23 // element from a sequence, instead of merely the first non-null.
24 var CoalesceFuncscip-go gomod github.com/hashicorp/go-cty-funcs . `github.com/hashicorp/go-cty-funcs/collection`/CoalesceFunc. = functionscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty/function`/.Newscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty/function`/New().(&functionscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty/function`/.Specscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty/function`/Spec#{
25 Paramsscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty/function`/Spec#Params.: []functionscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty/function`/.Parameterscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty/function`/Parameter#{},
26 VarParamscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty/function`/Spec#VarParam.: &functionscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty/function`/.Parameterscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty/function`/Parameter#{
27 Namescip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty/function`/Parameter#Name.: "vals",
28 Typescip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty/function`/Parameter#Type.: ctyscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/.DynamicPseudoTypescip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/DynamicPseudoType.,
29 AllowUnknownscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty/function`/Parameter#AllowUnknown.: true,
30 AllowDynamicTypescip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty/function`/Parameter#AllowDynamicType.: true,
31 AllowNullscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty/function`/Parameter#AllowNull.: true,
32 },
33 Typescip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty/function`/Spec#Type.: func(argsscip-go gomod github.com/hashicorp/go-cty-funcs . `github.com/hashicorp/go-cty-funcs/collection`/CoalesceFunc:args. []ctyscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/.Valuescip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/Value#) (retscip-go gomod github.com/hashicorp/go-cty-funcs . `github.com/hashicorp/go-cty-funcs/collection`/CoalesceFunc:ret. ctyscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/.Typescip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/Type#, errscip-go gomod github.com/hashicorp/go-cty-funcs . `github.com/hashicorp/go-cty-funcs/collection`/CoalesceFunc:err. error) {
34 argTypes := make([]ctyscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/.Typescip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/Type#, len(argsscip-go gomod github.com/hashicorp/go-cty-funcs . `github.com/hashicorp/go-cty-funcs/collection`/CoalesceFunc:args.))
35 for i, val := range argsscip-go gomod github.com/hashicorp/go-cty-funcs . `github.com/hashicorp/go-cty-funcs/collection`/CoalesceFunc:args. {
36 argTypes[i] = val.Typescip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/Value#Type().()
37 }
38 retType, _ := convertscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty/convert`/.UnifyUnsafescip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty/convert`/UnifyUnsafe().(argTypes)
39 if retType == ctyscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/.NilTypescip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/NilType. {
40 return ctyscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/.NilTypescip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/NilType., errorsscip-go gomod github.com/golang/go/src go1.24.0 errors/.Newscip-go gomod github.com/golang/go/src go1.24.0 errors/New().("all arguments must have the same type")
41 }
42 return retType, nil
43 },
44 Implscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty/function`/Spec#Impl.: func(argsscip-go gomod github.com/hashicorp/go-cty-funcs . `github.com/hashicorp/go-cty-funcs/collection`/CoalesceFunc:args. []ctyscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/.Valuescip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/Value#, retTypescip-go gomod github.com/hashicorp/go-cty-funcs . `github.com/hashicorp/go-cty-funcs/collection`/CoalesceFunc:retType. ctyscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/.Typescip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/Type#) (retscip-go gomod github.com/hashicorp/go-cty-funcs . `github.com/hashicorp/go-cty-funcs/collection`/CoalesceFunc:ret. ctyscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/.Valuescip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/Value#, errscip-go gomod github.com/hashicorp/go-cty-funcs . `github.com/hashicorp/go-cty-funcs/collection`/CoalesceFunc:err. error) {
45 for _, argVal := range argsscip-go gomod github.com/hashicorp/go-cty-funcs . `github.com/hashicorp/go-cty-funcs/collection`/CoalesceFunc:args. {
46 // We already know this will succeed because of the checks in our
47 // Type func above
48 argVal, _ = convertscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty/convert`/.Convertscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty/convert`/Convert().(argVal, retTypescip-go gomod github.com/hashicorp/go-cty-funcs . `github.com/hashicorp/go-cty-funcs/collection`/CoalesceFunc:retType.)
49 if !argVal.IsKnownscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/Value#IsKnown().() {
50 return ctyscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/.UnknownValscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/UnknownVal().(retTypescip-go gomod github.com/hashicorp/go-cty-funcs . `github.com/hashicorp/go-cty-funcs/collection`/CoalesceFunc:retType.), nil
51 }
52 if argVal.IsNullscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/Value#IsNull().() {
53 continue
54 }
55 if retTypescip-go gomod github.com/hashicorp/go-cty-funcs . `github.com/hashicorp/go-cty-funcs/collection`/CoalesceFunc:retType. == ctyscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/.Stringscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/String. && argVal.RawEqualsscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/Value#RawEquals().(ctyscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/.StringValscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/StringVal().("")) {
56 continue
57 }
58
59 return argVal, nil
60 }
61 return ctyscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/.NilValscip-go gomod github.com/zclconf/go-cty v1.17.0 `github.com/zclconf/go-cty/cty`/NilVal., errorsscip-go gomod github.com/golang/go/src go1.24.0 errors/.Newscip-go gomod github.com/golang/go/src go1.24.0 errors/New().("no non-null, non-empty-string arguments")
62 },
63 })