Skip to content
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

merge_with raises err on no inputs #73

Merged
merged 4 commits into from
Nov 8, 2013

Conversation

mrocklin
Copy link
Member

@mrocklin mrocklin commented Nov 7, 2013

This allows merge_with to interoperate with curry but fails on the possible base case merge_with(func) == {}

@@ -36,6 +36,9 @@ def merge_with(fn, *dicts):
See Also:
merge
"""
if len(dicts) == 0:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why isn't this a NOP if dicts is empty? That is what Clojure's merge-with does (returns nil).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup. That's the controversy. Normally this would return {}. This screws up curry though because merge_with(sum) actually works and so we don't close sum into the function. There are competing objectives. I'm not sure which way is best.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, you can probably predict where my prejudice falls :-) [clojure-like semantics]

Let’s see if @eriknw has a (tiebreaker?) opinion.

On Nov 7, 2013, at 3:21 PM, Matthew Rocklin notifications@github.com wrote:

In toolz/dicttoolz/core.py:

@@ -36,6 +36,9 @@ def merge_with(fn, *dicts):
See Also:
merge
"""

  • if len(dicts) == 0:
    Yup. That's the controversy. Normally this would return {}. This screws up curry though because merge_with(sum) actually works and so we don't close sum into the function. There are competing objectives. I'm not sure which way is best.


Reply to this email directly or view it on GitHub.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The right thing here is probably for me to be forced to make a special curried implementation of merge_with within the curried.py file.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps it would be useful to have a HOF that changes variadic arguments to a single iterable argument.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be useful. concat and concatv is a good use case.

On Thu, Nov 7, 2013 at 1:44 PM, Erik Welch notifications@github.com wrote:

In toolz/dicttoolz/core.py:

@@ -36,6 +36,9 @@ def merge_with(fn, *dicts):
See Also:
merge
"""

  • if len(dicts) == 0:

Perhaps it would be useful to have a HOF that changes variadic arguments
to a single iterable argument.


Reply to this email directly or view it on GitHubhttps://github.com//pull/73/files#r7511342
.

@eriknw
Copy link
Member

eriknw commented Nov 7, 2013

Since I'm on the spot, I would say keep the old behavior (at least for now). This raises two things I've been contemplating:

  1. variadic curry
  2. why it's generally a bad idea to compare toolz functions to the builtins sum and min

@mrocklin
Copy link
Member Author

mrocklin commented Nov 7, 2013

See new commit. Standard merge_with null behavior is preserved. The toolz.curried.merge_with(func) returns a curried function, not {} with the thought that this is what is more commonly intended.

Again, old behavior is preserved in standard namespace. New behavior is isolated to curried namespace.

@@ -37,7 +37,7 @@ def nargs(f):


def should_curry(f):
do_curry = set((toolz.map, toolz.filter))
do_curry = set((toolz.map, toolz.filter, toolz.merge_with))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is now unnecessary since merge_with is defined below.

@mrocklin
Copy link
Member Author

mrocklin commented Nov 8, 2013

I'm planning to merge this early in the morning if no comments.

Conflicts:
	toolz/tests/test_curried.py
@mrocklin
Copy link
Member Author

mrocklin commented Nov 8, 2013

I lied. I'm merging this now. We can revert the behavior in the future if necessary.

mrocklin added a commit that referenced this pull request Nov 8, 2013
merge_with raises err on no inputs
@mrocklin mrocklin merged commit 5d59d50 into pytoolz:master Nov 8, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants