Functions depending on other Functions
package main
import (
"fmt"
)
func main() {
a := myFloats{1.0, 2.0, 3.0}
fmt.Println(a.First())
}
//go:generate pie myFloats.First
type myFloats []float64
yields
./myfloats_pie.go:5:11: ss.FirstOr undefined (type myFloats has no field or method FirstOr)
Currently, the developer hits this error and figures out they must explicitly ask for FirstOr:
//go:generate pie myFloats.First.FirstOr
It would be nice if Pie somehow knew it requires to generate FirstOras a dependency for First. I'm not saying this is trivial though, and also the inconvenience is minor.
Generating all Pie functions with
//go:generate pie myType.*
seems to be the best choice in general.
My measurements confirm that the final compiled binary is not bigger when lots a unused functions are generated. Unused funcs are correctly discarded by the compiler.
Ah, that's a good catch. I have thought before about how to handle this because there are several other cases where some functions would be easier to implement if they could use other functions that may not be included.
One solution I can think of right now is to add dependencies when registering the functions:
// functions/main.go
{"First", "first.go", ForAll, []string{"FirstOr"}},
The pie command has to build a list of functions anyway (from CLI args), this shouldn't be too hard to merge with the existing list.