summaryrefslogtreecommitdiff
path: root/sortFunc.go
diff options
context:
space:
mode:
Diffstat (limited to 'sortFunc.go')
-rw-r--r--sortFunc.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/sortFunc.go b/sortFunc.go
index 869a2ab..df52114 100644
--- a/sortFunc.go
+++ b/sortFunc.go
@@ -193,6 +193,25 @@ func (pf *File) appendUnique(w io.Writer) {
fmt.Fprintln(w, "")
}
+func appendUniqueBy(w io.Writer, FRUIT, APPLES, APPLE, COLOR, FruitLock string) {
+ fmt.Fprintln(w, "// TESTING")
+ fmt.Fprintln(w, "// enforces "+APPLE+"."+COLOR+" is unique in "+FRUIT+"."+APPLES)
+ fmt.Fprintln(w, "func (x *"+FRUIT+") AppendUniqueBy"+COLOR+"(newP *"+APPLE+") bool {")
+ fmt.Fprintln(w, " "+FruitLock+".Lock()")
+ fmt.Fprintln(w, " defer "+FruitLock+".Unlock()")
+ fmt.Fprintln(w, "")
+ fmt.Fprintln(w, " for _, p := range x."+APPLES+" {")
+ fmt.Fprintln(w, " if p."+COLOR+" == newP."+COLOR+" {")
+ fmt.Fprintln(w, " return false")
+ fmt.Fprintln(w, " }")
+ fmt.Fprintln(w, " }")
+ fmt.Fprintln(w, "")
+ fmt.Fprintln(w, " x."+APPLES+" = append(x."+APPLES+", newP)")
+ fmt.Fprintln(w, " return true")
+ fmt.Fprintln(w, "}")
+ fmt.Fprintln(w, "")
+}
+
func (pf *File) replaceFunc(w io.Writer) {
var MSG string = pf.Bases.Name
var BASE string = pf.Base.Name