RFC: separate utils library on core types #932
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
NOT INTENDED FOR MERGING, JUST FOR DISCUSSION.
There are a bunch of common/pythonic things one would want to do on core types that we don't provide pre-existing functionality for. I think we should provide it in some way.
The limitations are primarily that without some kind of trait/type class system it is hard to provide this stuff generically (e.g. functions that work for all iterators over some type). Given this is something Guppy may add in future, I am reluctant to include things in the standard library.
I propose instead providing this from a separate package that isn't tied to language stability or maintenance. This package:
In this RFC PR I have collected some such functions I had lying around. It includes:
I have taken the approach of making these functions look like common python equivalents. But the resemblance is superficial since they only work on types. An alternative approach is to make them methods on the array type, rust style, which might make it more palatable for the standard library but with the obvious downside that people won't naturally find them and use them.
Some missing things I'd like to add: