summaryrefslogtreecommitdiff
path: root/generateSort.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-01-12 02:38:17 -0600
committerJeff Carr <[email protected]>2025-01-12 02:38:17 -0600
commit47d2a95bc5b6990de924e66b37dbb5affb4c3cd4 (patch)
treecf299e7e6020b7c6b46a01bf9a98231885dd09d6 /generateSort.go
parentcfd9ec5ccddded628f4f9bf95beefc11dcfeb51b (diff)
it compiled the test. sort seems to be working
Diffstat (limited to 'generateSort.go')
-rw-r--r--generateSort.go20
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
}