@@ -135,6 +135,24 @@ func ExampleEnv_tagged_field_names() {
135135 // Output : Hello World
136136}
137137
138+ func ExampleAsKind () {
139+ program , err := expr .Compile ("{a: 1, b: 2}" , expr .AsKind (reflect .Map ))
140+ if err != nil {
141+ fmt .Printf ("%v" , err )
142+ return
143+ }
144+
145+ output , err := expr .Run (program , nil )
146+ if err != nil {
147+ fmt .Printf ("%v" , err )
148+ return
149+ }
150+
151+ fmt .Printf ("%v" , output )
152+
153+ // Output: map[a:1 b:2]
154+ }
155+
138156func ExampleAsBool () {
139157 env := map [string ]int {
140158 "foo" : 0 ,
@@ -169,8 +187,8 @@ func ExampleAsBool_error() {
169187 // Output: expected bool, but got int
170188}
171189
172- func ExampleAsFloat64 () {
173- program , err := expr .Compile ("42" , expr .AsFloat64 ())
190+ func ExampleAsInt () {
191+ program , err := expr .Compile ("42" , expr .AsInt ())
174192 if err != nil {
175193 fmt .Printf ("%v" , err )
176194 return
@@ -182,17 +200,9 @@ func ExampleAsFloat64() {
182200 return
183201 }
184202
185- fmt .Printf ("%v" , output .(float64 ))
186-
187- // Output: 42
188- }
203+ fmt .Printf ("%T(%v)" , output , output )
189204
190- func ExampleAsFloat64_error () {
191- _ , err := expr .Compile (`!!true` , expr .AsFloat64 ())
192-
193- fmt .Printf ("%v" , err )
194-
195- // Output: expected float64, but got bool
205+ // Output: int(42)
196206}
197207
198208func ExampleAsInt64 () {
@@ -217,6 +227,32 @@ func ExampleAsInt64() {
217227 // Output: 5
218228}
219229
230+ func ExampleAsFloat64 () {
231+ program , err := expr .Compile ("42" , expr .AsFloat64 ())
232+ if err != nil {
233+ fmt .Printf ("%v" , err )
234+ return
235+ }
236+
237+ output , err := expr .Run (program , nil )
238+ if err != nil {
239+ fmt .Printf ("%v" , err )
240+ return
241+ }
242+
243+ fmt .Printf ("%v" , output .(float64 ))
244+
245+ // Output: 42
246+ }
247+
248+ func ExampleAsFloat64_error () {
249+ _ , err := expr .Compile (`!!true` , expr .AsFloat64 ())
250+
251+ fmt .Printf ("%v" , err )
252+
253+ // Output: expected float64, but got bool
254+ }
255+
220256func ExampleOperator () {
221257 code := `
222258 Now() > CreatedAt &&
0 commit comments