Apply applies eval to vecs. If any element of vecs is a Dynamic, Apply rips vecs accordingly, applies eval to the ripped vectors, and stitches the results together into a Dynamic. If ripUnions is true, Apply also rips Unions.
(ripUnions bool, eval func(...Any) Any, vecs ...Any)
| 9 | // results together into a Dynamic. If ripUnions is true, Apply also rips |
| 10 | // Unions. |
| 11 | func Apply(ripUnions bool, eval func(...Any) Any, vecs ...Any) Any { |
| 12 | if ripUnions { |
| 13 | for k, vec := range vecs { |
| 14 | if union, ok := Under(vec).(*Union); ok { |
| 15 | vecs[k] = union.Dynamic |
| 16 | } |
| 17 | } |
| 18 | } |
| 19 | d, ok := findDynamic(vecs) |
| 20 | if !ok { |
| 21 | return eval(defuse(vecs)...) |
| 22 | } |
| 23 | results := make([]Any, len(d.Values)) |
| 24 | for i, ripped := range rip(vecs, d) { |
| 25 | if len(ripped) > 0 { |
| 26 | results[i] = Apply(ripUnions, eval, ripped...) |
| 27 | } |
| 28 | } |
| 29 | return stitch(d.Tags, results) |
| 30 | } |
| 31 | |
| 32 | func findDynamic(vecs []Any) (*Dynamic, bool) { |
| 33 | for _, vec := range vecs { |
no test coverage detected