-
-
Couldn't load subscription status.
- Fork 299
Add array::zip and Related Macros
#2370
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
Conversation
|
Can you add something about this in the releasenotes? |
|
Can we change zip to: macro zip(Allocator allocator, left, right, bool extend = false, fill_with = EMPTY_MACRO_SLOT) @nodiscard
{ ... }Because then we get: Pair{String, long}[] zipped = array::tzip(left, right, "aaa", extend: true);
...
(void)array::tzip(left, right, extend: true, fill_with: (TestStructZip){100, 200}));This would reduce the number of macros and to me it feels a little more succinct, especially since "zip_longest" isn't a super clear name, and it would reduce it to zip, zip with, zip into. Possibly we could even do: macro zip(Allocator allocator, left, right, func = EMPTY_MACRO_SLOT, bool extend = false, fill_with = EMPTY_MACRO_SLOT) @nodiscardSo there's just zip and zip_into |
|
Thanks for bringing my attention to this. I will address consolidating the code some more this morning. Looking at it again after some time has passed (with fresh 👀), I agree that pulling
Edit: Naww, allow me to vacillate on this again and say, yeah, if the user is passing a function pointer or lambda, they know what to expect as a return result. We are now down to just |
…inters. - Deprecate `add_array` in favour of `push_all` on lists. - Add support for generic lists for zip.
Adding
zipandzipWithfunctional-style macros to thestd::core::arraymodule. Take a look at the unit tests and documentation provided to understand how these are working.Also added a builtin slice cloning function (and a passthrough variant for the temp allocator).
My original use-case for these was to quickly allow the application and assignment of simple operators between slices, a la:
This can now be achieved with:
And inlining these operations with user-defined types that have
@operatoroverloads will be nice to have.Plain
zipvariants:zipWithvariants:zipWithInto, no allocations necessary: