Every runs the passed function for all the key value pairs in the object. If assertion inside function fails, the original Object is marked failed. Every will execute the function for all values in the object irrespective of assertion failures for some values in the object. The function is invoke
(fn func(key string, value *Value))
| 400 | // value.String().NotEmpty() |
| 401 | // }) |
| 402 | func (o *Object) Every(fn func(key string, value *Value)) *Object { |
| 403 | opChain := o.chain.enter("Every()") |
| 404 | defer opChain.leave() |
| 405 | |
| 406 | if opChain.failed() { |
| 407 | return o |
| 408 | } |
| 409 | |
| 410 | if fn == nil { |
| 411 | opChain.fail(AssertionFailure{ |
| 412 | Type: AssertUsage, |
| 413 | Errors: []error{ |
| 414 | errors.New("unexpected nil function argument"), |
| 415 | }, |
| 416 | }) |
| 417 | return o |
| 418 | } |
| 419 | |
| 420 | for _, kv := range o.sortedKV() { |
| 421 | func() { |
| 422 | valueChain := opChain.replace("Every[%q]", kv.key) |
| 423 | defer valueChain.leave() |
| 424 | |
| 425 | fn(kv.key, newValue(valueChain, kv.val)) |
| 426 | }() |
| 427 | } |
| 428 | |
| 429 | return o |
| 430 | } |
| 431 | |
| 432 | // Filter accepts a function that returns a boolean. The function is ran |
| 433 | // over the object elements. If the function returns true, the element passes |