4 ms·
I know all of these things... My brain just does not like the squishiness in most cases, or how silly and contrived most examples that I have seen are.
by megaman22 9y ago
I know all of these things... My brain just does not like the squishiness in most cases, or how silly and contrived most examples that I have seen are.
- emodendroket 9y agoWell they're contrived because a realistic example would have a ton of code having nothing to do with the concept
- megaman22 9y agoWell, in that case, they are of little more value than the equally contrived OOP examples we grew up with, with a base Fruit class, and Banana and Apple subclasses. Stupid examples are in many cases worse than no examples at all.
- emodendroket 9y agoWell I'm afraid I can't agree there. But like I said, the shower interpolate service is a real-world example and the purpose seems clear enough (why evaluate the string each time?)
- megaman22 9y agoIf there actually was an example where that measure of ceremony was involved and was worthwhile, I'm too dumb too have understood it.
- emodendroket 9y agohttps://docs.angularjs.org/api/ng/service/$interpolate https://docs.angularjs.org/api/ng/service/$interpolate
- posterboy 9y agoI'm sorry, "shower" can not be found in the featured article.
- emodendroket 9y agoWeird auto-correct issues from posting on the phone, but I meant to say "angular"
- 59nadir 9y agoLearn and use Haskell/OCaml/ReasonML/Elm and you'll get it. It's daft to use currying in languages that don't have a good base for supporting it.
- coltonv 9y agoHere's the simplest example I can come up with, and it's something I do all the time. I have an array of objects in my state. For this example we'll say they are Todos, and each one has three properties, id, name, and checked. I have a function `checkTodo` with the signature `checkTodo(id: string, event: InputEvent)` that I want to call if one of those Todos is checked. So say I'm using React. I can use arrow functions like this: todos.map((todo) => <input type="checkbox" onChange={ (event) => checkTodo(todo.id, event) } checked={ todo.checked } /> <label>{ todo.name } ) That's okay, but having arrow functions like that in JSX (which you'll have several of in a complex application) can get a bit unwieldy. Currying gives us another option that can be cleaner and avoids having to declare functions inside our render. If we change our method signature to this: `checkTodo = (id: string) => (event: InputEvent)` then we can write our JSX like this: todos.map((todo) => <input type="checkbox" onChange={ checkTodo(todo.id) } checked={ todo.checked } /><label>{ todo.name } ) It's a bit cleaner, and can make certain patterns a lot easier in the long run. For example, say we make a shared <Todo /> component like the one above which can be rendered both in a list, as above, or on it's own. In that case, it would be bad for the method signature that the Todo component expects to be the id and event, as the id wouldn't be necessary when we're not working with an array. Instead, currying means our Todo component can simply expect a function that takes in an InputEvent, and currying can move the other logic where it's needed. Does that make sense? If you don't know React I could rewrite this using native DOM calls.