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.
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
Add _apply_list_op, each, map, filter to ComplexBase #47
base: main
Are you sure you want to change the base?
Add _apply_list_op, each, map, filter to ComplexBase #47
Changes from 4 commits
16fb405
f42db68
a5e217f
46cf21f
0afacb5
045ea7b
4cfe915
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A return signature of either the value (like
dict.values
) or a tuple of the key and the value(attr, value)
(likedict.items
) would be more straightforward. Maybe we can make them two separate methods.But if we do this, we can no longer make
remove_invalid
,remove_duplicate
andsort
work using this, right?Or we could keep this unchanged and have two public wrappers
lists
andlists_with_names
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I would definitely keep this and internal function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Type checking can be simplified if we change the return signature into
Iterator[Tuple[str, List]]
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there must be a bug in mypy, it was complaining about things whose type is actually known...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this might be problematic as it will keep reusing the generator created at
__init__
. We probably don't want this behavior. Also, I am not a fan of havingflat
as a property. Could we simply make itMusic.lists()
, which is rather straightforward from its name except that it's recursive?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, I didn't realize that.
How about this?
flat
is now reusable, and it's always the same object, so it's not a problem to have it as a property.If you still insist on it being a function, why not call it e.g.
walk_lists
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just want it to behave more like
dict.items()
ordict.values()
rather thannumpy.ndarray.flat
ormusic21.stream.Stream.flat
. It's quite common in Python to have a function that returns an iterator.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True. Is
walk_lists()
OK then? The name should give a hint that the return value is good only for (one) iteration.BTW
dict.items()
anddict.values()
also return objects that support more than just iteration (e.g.len()
).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually,
lists()
suggests that it would iterate over lists. But myflat
iterates over list items, not lists themselves. So we need a better name. I thinkflat()
(just changing the property to a function) orwalk_lists()
is OK.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made it
list_items()
and addedlist()
to iterate over the actual lists.