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

Added divide and modulo operators #1593

Merged
merged 8 commits into from Mar 15, 2023
Merged

Conversation

teejaded
Copy link
Contributor

@teejaded teejaded commented Mar 9, 2023

fixes #49

@teejaded teejaded changed the title Added divide operator Added divide and modulo operators Mar 9, 2023
document: "a: !horse cat_meow\nb: !goat _",
expression: `.a = .a / .b`,
expected: []string{
"D0, P[], (doc)::a: !horse\n - cat\n - meow\nb: !goat _\n",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in this case I think it'd be more correct if a is an array, but each element is a horse

Copy link
Contributor Author

@teejaded teejaded Mar 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The behavior came from string split. Should I try to fix it there?

echo $'a: !horse cat_meow\nb: !goat _' | yq '.a | split("_")'
- cat
- meow

❯ echo $'a: !horse cat_meow\nb: !goat _' | yq '.a = (.a |split("_"))'
a: !horse
  - cat
  - meow
b: !goat _

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh I see - yeah I think so 🤔 , that would be appreciated

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I'm not sure I can change it easily. It seems the assignment operator won't change custom tags. Changing that would be a breaking change.

echo $'a: !horse cat_meow\nb: !goat _' | yq '.a = {} | .c = {} | .[] | tag'
!horse
!goat
!!map

❯ echo $'a: !horse cat_meow\nb: !goat _' | yq '.a = {} | .c = {} | .c = [] | .[] | tag'
!horse
!goat
!!seq

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alright - leave it, no worries

@mikefarah
Copy link
Owner

Thanks @teejaded - this looks promising :)

@mikefarah
Copy link
Owner

Couple of failures in the pipeline - should be easy to fix. Just run make local build to reproduce

@teejaded
Copy link
Contributor Author

I think it's fixed now! Sorry I neglected that step from CONTRIBUTING.md.

@mikefarah mikefarah merged commit a466821 into mikefarah:master Mar 15, 2023
3 checks passed
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

Successfully merging this pull request may close these issues.

Add support for Operator '*, /, and %'
2 participants