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

Remap enumerating/looping RFC #6031

Closed
binarylogic opened this issue Jan 13, 2021 · 6 comments
Closed

Remap enumerating/looping RFC #6031

binarylogic opened this issue Jan 13, 2021 · 6 comments
Assignees
Labels
domain: vrl Anything related to the Vector Remap Language needs: rfc Needs an RFC before work can begin. type: task Generic non-code related tasks

Comments

@binarylogic
Copy link
Contributor

We need an RFC that obtains consensus on our approach to enumerating/looping in Remap. There are a few open issues that require this (#5377, #5784, #5783, #5852), and we've had a number of discussions floating around (#5852 (comment)). Once we decide on an approach we should update the referenced tickets to reflect it.

Note: this is not blocking 0.12. We will be shipping 0.12 without this feature.

@jszwedko
Copy link
Member

Just putting this here so I don't lose it again: https://github.com/josevalim/nested-data-structure-traversal

Examples of mapping / iteration in a bunch of languages.

@binarylogic
Copy link
Contributor Author

binarylogic commented May 13, 2021

That project is very interesting! For posterity, Lua and Python are my favorite due to their immediately obvious and simple nature. I get that we'd need to discuss low-level changes to the language, but from a pure readability perspective those are my favorite.

@JeanMertz
Copy link
Contributor

ref #8381

@dbcfd
Copy link
Contributor

dbcfd commented Sep 14, 2021

Given that arrays have a push capability, could a simple first pass just be

acc = []
for obj in .array {
  obj.new_field = 1
  push(acc, obj)
}

More complicated functions could be built later, but this seems like it would solve a lot of use cases.

This would be the iterate without index case in #5875

For example, to iterate with index

idx = 0
acc = []
for obj in .array {
  obj.idx = idx
  idx = idx + 1
  push(acc, idx)
}

@dbcfd
Copy link
Contributor

dbcfd commented Sep 15, 2021

Additionally, iterating an object could be accomplished with a tuple object

for kv in .object {
  .key = kv.0
  .value = kv.1
  }

@binarylogic
Copy link
Contributor Author

Closing in favor of #8381

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain: vrl Anything related to the Vector Remap Language needs: rfc Needs an RFC before work can begin. type: task Generic non-code related tasks
Projects
None yet
Development

No branches or pull requests

5 participants