-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Make reverse more DWIM-y #1748
base: master
Are you sure you want to change the base?
Make reverse more DWIM-y #1748
Conversation
Reversing strings totally makes sense! Boolean - it's weird. I'd not include it though, you have Numbers just don't make sense. If that's really what you want, I'd rather that you make it explicit in your code |
@davidfetter - Some observations: a) there is no reason to define $in in the body of the def; b) for strings, c) In my opinion, the proposed def is inappropriate for objects as the proposed operation is a kind of inversion or transposition. A more appropriate def (perhaps even the DWIM definition) would reverse the order of keys. In addition, this def makes it very easy for users to ignore all the issues that key/value inversion can present. If someone wants to invert keys and values in some fashion, they should be aware of all the issues, and be responsible for their resolution. d) I would go even further than @leonid-s-usov and argue that the domain of |
Yeah.. I’d say that anything “explodable” should be also “reversible”
If one defines explode for objects to be to_entries then yeah, reverse would change the order of keys.
Sent from mobile device, typos and false corrections are possible
Regards,
Leonid S. Usov
… On 25 Oct 2018, at 11:57, pkoppstein ***@***.***> wrote:
@davidfetter - Some observations:
a) there is no reason to define $in in the body of the def;
b) for strings, explode | reverse | implode is much faster (approx 2 times according to my measurements) and also significantly more economical with memory than using split/join;
c) In my opinion, the proposed def is inappropriate for objects as the proposed operation is a kind of inversion or transposition. A more appropriate def (perhaps even the DWIM definition) would reverse the order of keys. In addition, this def makes it very easy for users to ignore all the issues that key/value inversion can present. If someone wants to invert keys and values in some fashion, they should be aware of all the issues, and be responsible for their resolution.
d) I would go even further than @leonid-s-usov and argue that the domain of reverse should not be extended beyond arrays and strings, mainly to avoid bloat and duplication of function. The simplicity of explode|reverse|implode could even be taken as an argument against the wisdom of an extension to strings :-)
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
c3d6cd7
to
232c00a
Compare
I've trimmed the extension back just to strings and removed fat from the code. The behavior for other types is compatible with the current behavior. |
@davidfetter - The trimmed down def has three bugs in it (e.g. it still assumes $in has been defined). Also, to avoid the second type check, I'd suggest:
If you wanted to propose the behavior on JSON objects that reverses the order of keys:
By the way, please note that it will be up to the maintainers to decide whether and when to include your contribution. |
02bb1f2
to
3e7fa84
Compare
I really appreciate your patient help here. |
Strings now work. Other types' current behavior preserved.
3e7fa84
to
0b5da6e
Compare
Sure, why not. |
Related issue: #412. |
Strings and numbers go backward.
Booleans flip.
Objects switch keys and values.