Skip to content

Commit e0118c6

Browse files
Merge pull request #82 from logic-building/RestPtr_UserDefinedType
Auto-generated code has pointer version of function - Rest
2 parents 5a6e84b + 8c6b314 commit e0118c6

File tree

5 files changed

+155
-0
lines changed

5 files changed

+155
-0
lines changed

gofp/gofp.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,9 @@ func generateFPCode(pkg, dataTypes, imports string) (string, error) {
231231
template += template2.Rest()
232232
template = r.Replace(template)
233233

234+
template += template2.RestPtr()
235+
template = r.Replace(template)
236+
234237
template += template2.Reduce()
235238
template = r.Replace(template)
236239

internal/employee/fp.go

Lines changed: 42 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: 42 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: 42 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/template/rest.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,29 @@ func Rest<CONDITIONAL_TYPE>(l []<TYPE>) []<TYPE> {
2323
}
2424
`
2525
}
26+
27+
// RestPtr removes 1st item of the list and return new list having rest of the items
28+
func RestPtr() string {
29+
return `
30+
31+
// Rest<CONDITIONAL_TYPE> removes 1st item of the list and return new list having rest of the items
32+
func Rest<CONDITIONAL_TYPE>Ptr(l []*<TYPE>) []*<TYPE> {
33+
if l == nil {
34+
return []*<TYPE>{}
35+
}
36+
37+
len := len(l)
38+
if len == 0 || len == 1 {
39+
return []*<TYPE>{}
40+
}
41+
42+
newList := make([]*<TYPE>, len-1)
43+
44+
for i, v := range l[1:] {
45+
newList[i] = v
46+
}
47+
48+
return newList
49+
}
50+
`
51+
}

0 commit comments

Comments
 (0)