Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a reason why we cannot have a getter for array items? #742

Open
kanstantsin-chernik opened this issue Nov 24, 2021 · 2 comments
Open

Comments

@kanstantsin-chernik
Copy link

kanstantsin-chernik commented Nov 24, 2021

I like the idea of safe autogenerated getters. But every time I have to check the length of an array I am confused as this job is so routine and dumb that is a perfect match for a autogenerated wrapper.
Consider example

if len(val.GetArrayField()) > 0 {
  val.GetArrayfield()[0].GetSomeNestedField()
}

can become

val.GetArrayfieldItem(0).GetSomeNestedField()

All we need is to generate array getter like this:

func (Value *v) GetArrayfieldItem(int32 index) *Field
if v != nil && index >= 0 && len(val.ArrayField) > index {
  return val.ArrayField[index]
}
return nil

Is there any fundamental reasons why we cannot have array getters like this or nobody just got to do it?

@kanstantsin-chernik kanstantsin-chernik changed the title Is there a reason why we cannot have a getter for an array items? Is there a reason why we cannot have a getter for array items? Nov 24, 2021
@kanstantsin-chernik
Copy link
Author

@89z this is just one use case which is already supported. I have use cases when I need a very specific item and accessing it with nested structure becoming ugly. Also, this feature can be configurable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
@kanstantsin-chernik and others