add IterBy() functions
This commit is contained in:
parent
63a3d0dc24
commit
ce1f320032
|
@ -119,11 +119,9 @@ func (pb *Fruits) printTable() {
|
||||||
|
|
||||||
func (pb *Fruits) sortTable(i int) {
|
func (pb *Fruits) sortTable(i int) {
|
||||||
var count int
|
var count int
|
||||||
all := pb.SortByBrand()
|
for fruit := range pb.IterByBrand() {
|
||||||
for all.Scan() {
|
|
||||||
tmp := all.Next()
|
|
||||||
count += 1
|
count += 1
|
||||||
log.Printf("found %d %s %s\n", count, tmp.Brand, tmp.City)
|
log.Printf("found %d %s %s\n", count, fruit.Brand, fruit.City)
|
||||||
if count > i {
|
if count > i {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,6 +125,13 @@ func (pb *Files) makeNewSortfile(pf *File) error {
|
||||||
selectName := "selectAll" + VARNAME
|
selectName := "selectAll" + VARNAME
|
||||||
funcdef := pmsg.newSortBy(wSort, PARENT, s.VarType, sortname, sortby, selectName, v.VarName)
|
funcdef := pmsg.newSortBy(wSort, PARENT, s.VarType, sortname, sortby, selectName, v.VarName)
|
||||||
log.Printf("Adding %s\n", funcdef)
|
log.Printf("Adding %s\n", funcdef)
|
||||||
|
|
||||||
|
FRUITS := PARENT
|
||||||
|
FRUIT := s.VarType
|
||||||
|
SORTNAME := sortname
|
||||||
|
BRAND := v.VarName
|
||||||
|
funcdef = pmsg.addIterBy(wSort, FRUITS, FRUIT, BRAND, SORTNAME)
|
||||||
|
log.Printf("Adding %s\n", funcdef)
|
||||||
} else {
|
} else {
|
||||||
// deprecate this THIS DOES NOT MAKE SENSE TO DO
|
// deprecate this THIS DOES NOT MAKE SENSE TO DO
|
||||||
sortby = "Sort" + VARNAME + "By" + v.VarName
|
sortby = "Sort" + VARNAME + "By" + v.VarName
|
||||||
|
|
|
@ -116,6 +116,24 @@ func (msg *MsgName) newSortBy(w io.Writer, STRUCT, ITER, SORTNAME, SORTBY, SELEC
|
||||||
return funcdef
|
return funcdef
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (msg *MsgName) addIterBy(w io.Writer, FRUITS, FRUIT, APPLE, SORTNAME string) string {
|
||||||
|
fmt.Fprintln(w, "// for range syntax using iter package")
|
||||||
|
fmt.Fprintln(w, "func (x *"+FRUITS+") IterBy"+APPLE+"() iter.Seq[*"+FRUIT+"] {")
|
||||||
|
fmt.Fprintln(w, " items := x.selectAll"+FRUITS+"()")
|
||||||
|
fmt.Fprintln(w, " sort.Sort("+SORTNAME+"(items))")
|
||||||
|
fmt.Fprintln(w, " log.Println(\"Made Iter.Seq[] with length\", len(items))")
|
||||||
|
fmt.Fprintln(w, " return func(yield func(*"+FRUIT+") bool) {")
|
||||||
|
fmt.Fprintln(w, " for _, v := range items {")
|
||||||
|
fmt.Fprintln(w, " if !yield(v) {")
|
||||||
|
fmt.Fprintln(w, " return")
|
||||||
|
fmt.Fprintln(w, " }")
|
||||||
|
fmt.Fprintln(w, " }")
|
||||||
|
fmt.Fprintln(w, " }")
|
||||||
|
fmt.Fprintln(w, "}")
|
||||||
|
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
func (msg *MsgName) addAllFunc(w io.Writer, FRUIT, APPLE, APPLES string) string {
|
func (msg *MsgName) addAllFunc(w io.Writer, FRUIT, APPLE, APPLES string) string {
|
||||||
funcdef := "func (x *" + FRUIT + ") All() *" + APPLE + "Iterator {"
|
funcdef := "func (x *" + FRUIT + ") All() *" + APPLE + "Iterator {"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue