Subset returns a new function declaration which contains only the overloads with the specified IDs. If the subset function contains no overloads, then nil is returned to indicate the function is not functional.
(selector OverloadSelector)
| 232 | // If the subset function contains no overloads, then nil is returned to indicate the function is not |
| 233 | // functional. |
| 234 | func (f *FunctionDecl) Subset(selector OverloadSelector) *FunctionDecl { |
| 235 | if f == nil { |
| 236 | return nil |
| 237 | } |
| 238 | overloads := make(map[string]*OverloadDecl) |
| 239 | overloadOrdinals := make([]string, 0, len(f.overloadOrdinals)) |
| 240 | overloadDecls := make([]*OverloadDecl, 0, len(f.overloadDecls)) |
| 241 | for _, oID := range f.overloadOrdinals { |
| 242 | overload := f.overloads[oID] |
| 243 | if selector(overload) { |
| 244 | overloads[oID] = overload |
| 245 | overloadOrdinals = append(overloadOrdinals, oID) |
| 246 | overloadDecls = append(overloadDecls, overload) |
| 247 | } |
| 248 | } |
| 249 | if len(overloads) == 0 { |
| 250 | return nil |
| 251 | } |
| 252 | subset := &FunctionDecl{ |
| 253 | name: f.Name(), |
| 254 | doc: f.doc, |
| 255 | overloads: overloads, |
| 256 | singleton: f.singleton, |
| 257 | disableTypeGuards: f.disableTypeGuards, |
| 258 | state: f.state, |
| 259 | overloadOrdinals: overloadOrdinals, |
| 260 | overloadDecls: overloadDecls, |
| 261 | } |
| 262 | return subset |
| 263 | } |
| 264 | |
| 265 | // AddOverload ensures that the new overload does not collide with an existing overload signature; |
| 266 | // however, if the function signatures are identical, the implementation may be rewritten as its |