In mathematics and computer science, currying is the technique of converting a function that takes multiple arguments into a sequence of functions that each takes a single argument. For example, currying a function f that takes three arguments creates three functions:
or called in sequence:
(note that this syntax is not supported in MATLAB (sadly!), though it is in GNU Octave)
Given f, a function handle, and n, the number of input arguments to later be passed into f, create a function handle g that is a curried form of f. Similar to the above example:
> curriedMax = currify(@max,3);
> curriedMax(magic(5)); ans([]); ans('all')
ans =
25
> curriedMax(magic(3))([])('all') %only works in Octave
Both of these are equivalent to
> max(magic(5),[],'all')
Solution Stats
Problem Comments
Solution Comments
Show comments
Loading...
Problem Recent Solvers8
Suggested Problems
-
2609 Solvers
-
Project Euler: Problem 8, Find largest product in a large string of numbers
1327 Solvers
-
Matrix with different incremental runs
594 Solvers
-
Circular Primes (based on Project Euler, problem 35)
655 Solvers
-
Find the index of the largest value in any vector X=[4,3,4,5,9,12,0,4.....5]
401 Solvers
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!