(args []interface{})
| 158 | type Foreach struct{} |
| 159 | |
| 160 | func (f *Foreach) Call(args []interface{}) (interface{}, bool) { |
| 161 | if len(args) < 3 { |
| 162 | return false, false |
| 163 | } |
| 164 | |
| 165 | s := args[0] // iterable (slice or map) |
| 166 | if s == nil { |
| 167 | return false, false |
| 168 | } |
| 169 | |
| 170 | v, ok := args[1].(*BareBoundVariableLiteral) // item (variable) |
| 171 | if !ok { |
| 172 | return false, false |
| 173 | } |
| 174 | |
| 175 | e := args[2] // predicate (expression) |
| 176 | if e == nil { |
| 177 | return false, false |
| 178 | } |
| 179 | |
| 180 | var valuer = MapValuer{} |
| 181 | if len(args) > 3 { // optional predicate captures |
| 182 | for i := 3; i < len(args); i++ { |
| 183 | m, ok := args[i].(MapValuer) |
| 184 | if !ok { |
| 185 | continue |
| 186 | } |
| 187 | maps.Copy(valuer, m) |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | segments := make([]*BoundSegmentLiteral, 0) |
| 192 | |
| 193 | // obtain bound segments used in expression |
| 194 | var useCallValuer bool |
| 195 | walk := func(n Node) { |
| 196 | switch exp := n.(type) { |
| 197 | case *BoundSegmentLiteral: |
| 198 | segments = append(segments, exp) |
| 199 | case *Function: |
| 200 | useCallValuer = true |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | switch expr := e.(type) { |
| 205 | case *BinaryExpr: |
| 206 | WalkFunc(expr, walk) |
| 207 | case *NotExpr: |
| 208 | WalkFunc(expr, walk) |
| 209 | } |
| 210 | |
| 211 | switch elems := s.(type) { |
| 212 | case []string: |
| 213 | for _, elem := range elems { |
| 214 | if f.evalExpr(e, useCallValuer, f.stringMapValuer(v, elem), valuer) { |
| 215 | return true, true |
| 216 | } |
| 217 | } |
nothing calls this directly
no test coverage detected