Skip to content

pipe and **kwargs #510

Description

@dilzeem

Hi,

I am not sure if this something that should be done, or if this bad practice. But I wanted something like this to work.

import toolz

some_dict = {"hello": "world", "foo": "bar", "number": 0}

def first_func(hello, foo, **kwargs):
    hello = "John"
    foo = "baz"
    kwargs['newvalue'] = True
    return kwargs


def second_func(number, **kwargs):
    number = number + 1
    kwargs['number'] = number
    kwargs['anothervalue'] = False
    return kwargs


running something like this works:

first_func(**some_dict)
>>> 
{'number': 0, 'newvalue': True}
second_func(**some_dict)
>>> 
{'number': 1, 'anothervalue': False}

But this won't work, which I understand why.

new_dict = toolz.pipe(**some_dict, first_func, second_func)

The idea is that I want some_dict to remain untouched, but new_dict to capture relevant information along the way.

Is this bad practice? Or not a relevant usecase? or is there a better way to do this?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions