diff options
| author | Jeff Carr <[email protected]> | 2025-01-12 02:38:17 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-01-12 02:38:17 -0600 |
| commit | 47d2a95bc5b6990de924e66b37dbb5affb4c3cd4 (patch) | |
| tree | cf299e7e6020b7c6b46a01bf9a98231885dd09d6 /generateSort.go | |
| parent | cfd9ec5ccddded628f4f9bf95beefc11dcfeb51b (diff) | |
it compiled the test. sort seems to be working
Diffstat (limited to 'generateSort.go')
| -rw-r--r-- | generateSort.go | 20 |
1 files changed, 6 insertions, 14 deletions
diff --git a/generateSort.go b/generateSort.go index fd2291d..b92a4b1 100644 --- a/generateSort.go +++ b/generateSort.go @@ -87,25 +87,17 @@ func newSortType(w io.Writer, STRUCT, VARNAME string) string { return "type " + STRUCT + VARNAME + " []*" + STRUCT + " // { return a[i]." + VARNAME + " < a[j]." + VARNAME + " }" } -func newSortBy(w io.Writer, FRUIT, APPLE, APPLES, COLOR string) string { - funcdef := "func (x *" + FRUIT + ") SortBy" + COLOR + "() *" + APPLE + "Iterator // field: " + COLOR +func newSortBy(w io.Writer, STRUCT, ITER, SORTNAME, SORTBY, SELECT string) string { + funcdef := "func (x *" + STRUCT + ") " + SORTBY + "() *" + ITER + "Iterator" - fmt.Fprintln(w, "// START sort by ", COLOR, "(this is all you need once the Iterator is defined)") - fmt.Fprintln(w, "type "+APPLE+COLOR+" []*"+APPLE+"") - fmt.Fprintln(w, "") - fmt.Fprintln(w, "func (a "+APPLE+COLOR+") Len() int { return len(a) }") - fmt.Fprintln(w, "func (a "+APPLE+COLOR+") Less(i, j int) bool { return a[i]."+COLOR+" < a[j]."+COLOR+" }") - fmt.Fprintln(w, "func (a "+APPLE+COLOR+") Swap(i, j int) { a[i], a[j] = a[j], a[i] }") - fmt.Fprintln(w, "") - fmt.Fprintln(w, "func (x *"+FRUIT+") SortBy"+COLOR+"() *"+APPLE+"Iterator {") - fmt.Fprintln(w, " things := x.all"+APPLES+"()") + fmt.Fprintln(w, funcdef, "{") + fmt.Fprintln(w, " things := x."+SELECT+"()") fmt.Fprintln(w, "") - fmt.Fprintln(w, " sort.Sort("+APPLE+COLOR+"(things))") + fmt.Fprintln(w, " sort.Sort("+SORTNAME+"(things))") fmt.Fprintln(w, "") - fmt.Fprintln(w, " iterator := New"+APPLE+"Iterator(things)") + fmt.Fprintln(w, " iterator := New"+ITER+"Iterator(things)") fmt.Fprintln(w, " return iterator") fmt.Fprintln(w, "}") - fmt.Fprintln(w, "// END sort by", COLOR) return funcdef } |
