-
Notifications
You must be signed in to change notification settings - Fork 56
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
Enrich Radon by supporting new operators on maps, arrays and strings #2291
Comments
Does iterating on maps mean invoking the visiting function (subscript) on 2-item arrays with index 0 being occupied by each key and index 1 being occupied by each value? I see no other way to model it 🤔 |
This idea came up yesterday while assessing with @tmpolaczyk a possible solution to some user request. That you say would be already solved by converting a Map to an Array ("entries" operator?), I guess. The thing here is to avoid converting to an array for then converting back to a map, as to avoid also to deal with the ordering of fields and so on. So, "iterating on map" would mean to invoke the visiting subscript on every element of the JSON map, as is, with no conversion to an array of 2-element arrays involved. Surely, @tmpolaczyk can explain better. |
I mean, regardless of the map → array → map conversion, the visiting function still needs to have a contract, and taking into account that scripts cannot receive multiple arguments, I see no other way than what I described above. |
Sorry, now I get it. The visiting subscript would receive one single argument: the value for each entry (not the key). |
MapFilter could accept an array as input, this way we can filter by key or by value:
MapMap would be a bit more complicated, because mutating an array is more difficult. But should also be possible with the proposed ArrayAlter operator:
And MapAlter should have the same input as MapMap. For StringSlice I propose to do it the same way as Python, allowing negative indices to mean "starting from the end". |
You can find a work in progress implementation in this branch. |
When implementing StringHexToBytes I also implemented the reverse, BytesToHexString, but it turns out that operator already exists under the name BytesToString. That was a bit strange because I expected that operator to be the UTF8 encode/decode, not the bytes to hex that it currently is. Because there already exists an unimplemented StringToBytes operator, so to be consistent with BytesToString, that one should be the hex decode operator. I guess there is a possibility to treat hexadecimal as an encoding like UTF8, so we could define a new enum like: enum RadonStringEncoding {
Hex = 0,
Ascii = 1,
Utf8 = 2,
} And therefore StringHexToBytes would just be StringToBytes. And to convert strings to utf8 bytes, it would be StringToBytes(2), with 2 as the argument. While this solution would be a bit counter-intuitive, at least to me, it could be easily extended to support encodings like base64 or URL encoding (the %20 stuff from URLs). One limitation is that the operators will always convert bytes to string and string to bytes, and it may not be clear which one is encode and which one is decode. For example to encode a string as base64 it would be |
New Map operators:
New Array operators:
New String operators:
The text was updated successfully, but these errors were encountered: