Add helper functions for SQL(), Pos(), End()#120
Add helper functions for SQL(), Pos(), End()#120makenowjust merged 13 commits intocloudspannerecosystem:mainfrom
Conversation
makenowjust
left a comment
There was a problem hiding this comment.
I have a comment to lastElem. Other functions are acceptable.
ast/util.go
Outdated
|
|
||
| // Helper functions for Pos(), End() | ||
|
|
||
| // lastElem returns last element of slice s. |
There was a problem hiding this comment.
I understand your intention, but this function seems too generic. I would not want to add this as it could be used in places it is not supposed to be.
There was a problem hiding this comment.
OK, lastElem can be written as inline, so I will remove it.
(It may be possible to be accepted if T is restricted to Node)
-func lastElem[T any](s []T) T {
+func lastElem[T Node](s []T) T {There was a problem hiding this comment.
func last is acceptable.ElemNode[T Node](s []T) T {
There was a problem hiding this comment.
Introduce func lastNode[T Node](s []T) T in 47ea709
|
@apstndb If these PRs are merged, do you rewrite existing implementations with them as well? |
If you want to unify style of existing implementation immediately, I can rewrite them. |
|
I may be better to place functions into |
This sounds good 👍 |
This reverts commit e1a3e81.
Contributors need to maintain comments in
ast/ast.goand implementations ofSQL(),Pos(), andEnd()methods inast/sql.goandast/pos.go.I believe productability is improved if comments and implementations can be written as similar structure.
I propose to add helper functions to implement the methods.
I believe these functions are useful as long as memefish have
ast.Nodeinterface .Note
These helper functions are already used in PRs(#99, #101, #111).
sqlOptneedscomparableafter Go 1.20, so this PR bump Go version to 1.20.I have refacotored
ast.Select,ast.Pathandast.CallExprto demonstrate the usage and effect of helper functions.