Timeline for answer to What is 'Currying'? by Kyle
Current License: CC BY-SA 4.0
Post Revisions
31 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Nov 29, 2024 at 18:24 | comment | added | Steven Spark |
Can't you do that without currying? Like: const add3 = (b) => add(3,b); and using the rest/spread operator ... for multiple arguments... which is more flexible since you can substitute any argument at any position?
|
|
| Apr 11, 2024 at 15:53 | history | edited | Mike | CC BY-SA 4.0 |
formatting
|
| Aug 31, 2023 at 13:17 | comment | added | cppProgrammer | @Strawberry what a lovely sequence of comments! Nice to see helpful advice and questions followed by answers. | |
| Nov 15, 2022 at 11:47 | history | edited | crg | CC BY-SA 4.0 |
added 106 characters in body
|
| Jun 11, 2021 at 4:44 | history | edited | nCardot | CC BY-SA 4.0 |
added 4 characters in body
|
| Jun 11, 2021 at 4:36 | history | edited | nCardot | CC BY-SA 4.0 |
added 6 characters in body
|
| Feb 4, 2021 at 13:12 | comment | added | david_adler | "into a series of functions that each take only one argument". I often do a currying like pattern where I create a series of functions so that the top level function is cleaner but not all my functions have just one argument. Is it still currying? | |
| Sep 10, 2020 at 6:41 | comment | added | Abhi | consider in above answer,if you need to perform add(3,x) multiple times and your first parameter is always same (3) so you no need to call add(3,x) always. you can just call add3(4). | |
| S Jun 24, 2019 at 16:00 | history | suggested | Maarten ten Velden | CC BY-SA 4.0 |
Wikipedia says that "currying is the technique of translating the evaluation of a function that takes multiple arguments into evaluating a sequence of functions, each with a single argument". The original answer stated that each function takes part of the arguments, while it has to be a single one.
|
| Jun 24, 2019 at 15:00 | review | Suggested edits | |||
| S Jun 24, 2019 at 16:00 | |||||
| Jan 28, 2019 at 14:08 | comment | added | Kodragim | Currying is useful if you find you have a function where you are pass in a parameter which never changes. (Possibly a class with lots of reusable methods?) Instead of always passing in that same parameter, you curry the function to only pass in the parameters that do change | |
| Jan 27, 2018 at 14:21 | history | edited | OneCricketeer | CC BY-SA 3.0 |
added 3 characters in body
|
| Apr 27, 2017 at 20:36 | comment | added | aw04 | it's useful for caching arguments, maybe you need to call a function many times but the first argument will be the same or maybe that first argument maintains some sort of internal state in a closure | |
| Mar 22, 2017 at 11:25 | comment | added | Ahmed Eid | basically its a use case of closures .. close over one or more argument to make a more specialized function . | |
| Oct 2, 2016 at 16:50 | comment | added | Kyle Cronin |
@OscarRyz That doesn't look like currying to me. If you want to go with filtering, something like var greaterThan = x => y => y > x; would let you curry greaterThan so that you can use it like [1,2,3,4,5].filter(greaterThan(3)).
|
|
| Jun 4, 2016 at 20:11 | history | edited | mkobit | CC BY-SA 3.0 |
Add JavaScript markdown
|
| Mar 31, 2016 at 2:12 | comment | added | semicolon |
@Danny well what is more readable and concise? (lambda x: x + 5), (\x -> x + 5) etc. or (+ 5)? Because without currying you have to use the former for things like map (+ 5) [1, 2, 3, 4, 5].
|
|
| Feb 6, 2016 at 0:09 | history | edited | Kyle Cronin | CC BY-SA 3.0 |
Fix typo
|
| Feb 5, 2016 at 20:00 | comment | added | Zeek Aran | I'm a little late, but your code says 3+7=7. Thank you for the explanation though! | |
| Jan 30, 2016 at 2:02 | comment | added | Kyle Cronin | @SSHThis Do you know JavaScript? I edited this answer to use JS instead of Scheme. | |
| Jan 30, 2016 at 2:01 | history | edited | Kyle Cronin | CC BY-SA 3.0 |
switched from scheme to javascript because more people know that
|
| Jan 29, 2016 at 21:57 | comment | added | SSH This | Well thank you for the explanation, unfortunately the Scheme examples flew right over my head. | |
| Jan 27, 2016 at 10:02 | comment | added | lukas_o | @Strawberry probably for job interviews. ;) | |
| Sep 23, 2015 at 15:03 | comment | added | Danny | I still don't quite understand why you would want to do this. | |
| Jan 17, 2014 at 15:25 | comment | added | Doval | @Strawberry The nice thing about functional languages like Standard ML or Haskell is that you can get currying "for free". You can define a multi-argument function as you would in any other language, and you automatically get a curried version of it, without having to throw in a bunch of lambdas yourself. So you can produce new functions that take less arguments from any existing function without much fuss or bother, and that makes it easy to pass them to other functions. | |
| Jan 17, 2014 at 15:22 | comment | added | Doval |
@Strawberry The first argument to map must be a function that takes only 1 argument - an element from the list. Multiplication - as a mathematical concept - is a binary operation; it takes 2 arguments. However, in Haskell * is a curried function, similar to the second version of add in this answer. The result of (* 5) is a function that takes a single argument and multiplies it by 5, and that allows us to use it with map.
|
|
| Oct 26, 2013 at 23:11 | comment | added | Strawberry | I understand what the map function does, but I'm not sure if I understand the point you're trying to illustrate for me. Are you saying the map function represents the concept of currying? | |
| Oct 26, 2013 at 16:52 | comment | added | nyson |
@Strawberry, say for instance that you have a list of numbers in a [1, 2, 3, 4, 5] that you wish to multiply by an arbitrary number. In Haskell, I can write map (* 5) [1, 2, 3, 4, 5] to multiply the whole list by 5, and thus generating the list [5, 10, 15, 20, 25].
|
|
| Aug 8, 2013 at 18:00 | comment | added | Strawberry | In a practical sense, how can I make use this concept? | |
| Dec 19, 2012 at 1:44 | vote | accept | Ben | ||
| Aug 30, 2008 at 20:19 | history | answered | Kyle Cronin | CC BY-SA 2.5 |