Loading [Contrib]/a11y/accessibility-menu.js

Functional Programming explained to my grandma



Currying is one of the words you will hear the most when you start to work with functionnal programming. It is also one of the hardest to figure out.

*Definition: Currying is the technique of translating the evaluation of a function which takes multiple arguments into evaluating a sequence of functions, each with a single argument *

To keep it simple, we'll just focus on what currying is useful for. You have a function which takes many parameters. However, you may want to bind some parameters.

It improves code readability by partially applying some functions and giving names to specific uses.

Implement the multiply and multiplyByTwo
package example
* Created by charlotte on 13/05/17.
object CurryingObject {
def multiply(x : Int, y: Int):Int= ??? //TODO define a function who multiply x by y

Let's try with a clear-cut example. The area function defined take two parameters. Let's implement the specific case of the circle area and square area.

Implement the area computation
package example
* Created by charlotte on 15/06/17.
object Area {
def area(x : Double, y:Double):Double =(x, y) match { // it's pattern matching
// you can use it to define some differents implementations
Create your playground on Tech.io
This playground was created on Tech.io, our hands-on, knowledge-sharing platform for developers.
Go to tech.io
codingame x discord
Join the CodinGame community on Discord to chat about puzzle contributions, challenges, streams, blog articles - all that good stuff!
Online Participants