Skip to main content

All Questions

0 votes
2 answers
97 views

How can I implement the uncurry function on python?

I have function curry with arbitrary arity: def curry_explicit(function, arity): if arity == 0: return function def get_args(args): if len(args) == arity: return ...
Danil Totjmyanin's user avatar
3 votes
1 answer
146 views

What is the benefit of using curried/currying function in Functional programming?

If you consider inner_multiply as an initializer of multiply, shouldn't you make them loosely coupled and DI the initializer (or any other way) especially if you require multiple initializers? Or am I ...
Tando's user avatar
  • 845
0 votes
0 answers
84 views

Pass final positional argument in a curried function to the last parameter available

Given a simple curried function import toolz @toolz.curry def mklist(x, y, z): return [x, y, z] obviously calling mklist(x=1, y=2)(z=3) works. What I would like to be able to do is to call the ...
lupl's user avatar
  • 952
1 vote
0 answers
38 views

Use standard library or 3rd party to conviently uncurry Python functions

I am experimenting with Functional Programming in Python and I usually end up needing a way to uncurry functions. I solve this issue by using: from typing import Callable, TypeVar T = TypeVar("T&...
Ezequiel Castaño's user avatar
0 votes
0 answers
70 views

currying with python and lambda functiom

Let's say I have an procedural code in python like this, x = np.random.randint(0, 9, (4,4)) def foo(x): y = np.rot90(x) y = np.rot90(y) return y # This can be written as y = rot90(rot90(x)) ...
Jayendra Parmar's user avatar
0 votes
3 answers
967 views

How to create a function that applies a function to the inputs of another function in Python?

I'm looking for a nice functional way to do the following: def add(x, y): return x + y def neg(x): return -x def c(x, y): # Apply neg to inputs for add _x = neg(x) _y = neg(y) ...
timleathart's user avatar
2 votes
1 answer
451 views

Python curried function with variable number of arguments

Given n, I'd like to make a function which takes in n elements and returns them as a list. One way to do this: def g(n): def f(*l): assert len(l) == n return l return f My problem: I'd ...
Simon Alford's user avatar
  • 2,663
1 vote
2 answers
297 views

How to curry a function at a given argument position

Is it possible to curry a function at a user-defined n-th position? Functool's partial function can handle partial evaluation of multiple arguments that from functools import partial def f(x,y,z): ...
alancalvitti's user avatar
0 votes
1 answer
180 views

Can we use keyword arguments and curry until all arguments are received?

Can we use keyword arguments and curry a function until all arguments are received in any order? For example I have this code: def create_folder_transformer(folder): return lambda predicate: ...
Nishant's user avatar
  • 22k
10 votes
3 answers
4k views

How do I uncurry a function in Python?

Recently, I have studied 'Programming language' using standard ML, and I've learned currying method(or something), so I applied it in Python. The below is simple function and currying. def range_new(...
frhyme's user avatar
  • 1,036
1 vote
0 answers
72 views

Currying lambda functions in python [duplicate]

How can I curry lambda functions in Python. I am using Toolz library, but it provides currying functionality for normal functions only and not lambda functions
jgr0's user avatar
  • 727
1 vote
1 answer
111 views

Create new column depending on other columns: DRY and go functional

First: Maybe this fits better in code review, but I think here are more pandas affine users. Feel free to move it if you think otherwise It is often the case, that one wants to compute a new column ...
Quickbeam2k1's user avatar
  • 5,447
2 votes
2 answers
786 views

Function currying with Python fn module

I found this functional programming library fn and I found the following code for function currying >>> from fn.func import curried >>> @curried ... def sum5(a, b, c, d, e): ... ...
Adrián Juárez's user avatar
366 votes
10 answers
335k views

How does functools partial do what it does?

I am not able to get my head on how the partial works in functools. I have the following code from here: >>> sum = lambda x, y : x + y >>> sum(1, 2) 3 >>> incr = lambda y : ...
user1865341's user avatar
  • 4,539
109 votes
7 answers
106k views

How do I write a function that returns another function?

In Python, I'd like to write a function make_cylinder_volume(r) which returns another function. That returned function should be callable with a parameter h, and return the volume of a cylinder with ...
Julian Das's user avatar
  • 1,381

15 30 50 per page