Add while/until to standard library
This adds the while command from jq's standard library.
$ ./target/debug/jaq '[ while(. < 100; . * 2) ]' <<< 1
[
1,
2,
4,
8,
16,
32,
64
]
Fixed a typo that caused one more object to appear in comparison to jq, sorry.
Thanks a lot for your contribution!
Would you mind adding some tests for your new filters to jaq-std/tests/std.rs?
Done.
I found a difference between your implementation and jq's one: until(.; (1, 2)) with input null yields 1 2 with jq's builtin until, whereas with your implementation of until, it yields just 2.
Thanks for your tests, by the way.
Just to be clear: If you find a nice (read: jq-compliant and performant) way to implement until, then I'll be happy to merge your PR. :) But if not, then I'll be also fine with only merging your while implementation.
So far I don't see a way to implement until with just the existing functions without failing tests with commas. Guess I'll drop it.
Thanks a lot!
I felt inspired by your effort and implemented until in 9cda5b086507014d5d48074749d156bda71400f5 as core filter --- it turned out that this was just a slight generalisation of the recurse filter.
If you still have your tests for until, I would be happy to incorporate them, perhaps in a new pull request?
Ok, I went forward and incorporated your tests for until in c8190bb. Thanks again!