Skip to content

Commit 5a6e84b

Browse files
Merge pull request #81 from logic-building/DropLastPtr_UserDefinedType
Auto-generated code has pointer version of function - DropLast
2 parents 395d92a + 16fdf71 commit 5a6e84b

File tree

5 files changed

+127
-0
lines changed

5 files changed

+127
-0
lines changed

gofp/gofp.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,9 @@ func generateFPCode(pkg, dataTypes, imports string) (string, error) {
239239

240240
template += template2.DropLast()
241241
template = r.Replace(template)
242+
243+
template += template2.DropLastPtr()
244+
template = r.Replace(template)
242245
}
243246
return template, nil
244247
}

internal/employee/fp.go

Lines changed: 34 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/employer/fp.go

Lines changed: 34 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/gfp/fp.go

Lines changed: 34 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/template/droplast.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,25 @@ func DropLast<CONDITIONAL_TYPE>(list []<TYPE>) []<TYPE> {
2121
}
2222
`
2323
}
24+
25+
// DropLast is template to generate itself for different combination of data type.
26+
func DropLastPtr() string {
27+
return `
28+
// DropLast<CONDITIONAL_TYPE>Ptr drops last item from the list and returns new list.
29+
// Returns empty list if there is only one item in the list or list empty
30+
func DropLast<CONDITIONAL_TYPE>Ptr(list []*<TYPE>) []*<TYPE> {
31+
listLen := len(list)
32+
33+
if list == nil || listLen == 0 || listLen == 1 {
34+
return []*<TYPE>{}
35+
}
36+
37+
newList := make([]*<TYPE>, listLen-1)
38+
39+
for i := 0; i < listLen-1; i++ {
40+
newList[i] = list[i]
41+
}
42+
return newList
43+
}
44+
`
45+
}

0 commit comments

Comments
 (0)