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

add const function #282

Open
wcbeard opened this issue Oct 21, 2015 · 3 comments
Open

add const function #282

wcbeard opened this issue Oct 21, 2015 · 3 comments

Comments

@wcbeard
Copy link

wcbeard commented Oct 21, 2015

I haven't found a function in toolz to replicate Haskell's const function, that creates a function that returns a constant value.

Example usage would be

def const(v):
    return lambda *x, **k: v

f = const(5)
f(2)  # 5
f(3.14, [1, 3], a='whatever')  # 5

Unless I'm missing an existing function, would it be worthwhile to add something similar to the library?

@llllllllll
Copy link
Contributor

👍 I also commonly have a use for the const function. Do you think it should accept *args, **kwargs or just one positional arg? I think there is a case for either.

@wcbeard
Copy link
Author

wcbeard commented Oct 21, 2015

Hmm, good question. I think I'd prefer the more general *args, **kwargs style, just to avoid more TypeErrors at runtime.

It seems like it could generalize to more uses, but I guess I don't have a strong opinion.

@llllllllll
Copy link
Contributor

I also think the *args, **kwargs is more general. I just wanted to bring it up in case someone had a strong reason to not allow it.

machinelearningdeveloper added a commit to machinelearningdeveloper/toolz that referenced this issue Oct 22, 2015
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

No branches or pull requests

2 participants