Where Can I Sell My Phone? The Best Places to Earn the Most

Maybe you have an old phone lying around inside a drawer, buried beneath old cables and tech supplies you don’t need anymore. You keep saying you’ll get around to it, but it just sits there…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Implementing a curry function in JavaScript

If you are a functional programming enthusiast or a JavaScript or Scala developer, you might have heard about curried functions. What exactly is currying, how are they useful, how can I implement a simple curry function. Let’s take a look

Arity is the number of arguments a function expects. In JavaScript, function.length gives you the arity of the function. So, in simple words when we don’t provide arity number of arguments to a curried function, it will return you another function that expects the remaining function arguments.

We have a logger function that expects three arguments, background and font color of the message to be logged and finally the message string.

If we want to log some message we would normally do it like this

Notice how we have to pass ‘bgBlue’ in both the cases, isn't it a bit redundant especially if we intend to log messages with background blue in many places in our program. Here comes the use of a curried function.

Suppose we have a curry generator function (curry), we could do something like this

Notice how we have only passed “bgBlue” once. Now we can use the new function…

Add a comment

Related posts:

Veritas et Mendacium?

When I practiced law, I had to take the facts as they came and craft the most credible story that served my client’s interests. In civil rights law, I was often representing individuals who had no…

Can I perfume my Dog?

I love it when the home smells like a holiday. Cosy, warm and inviting with all of my favourite scents in one place! I must admit that most of us are addicted to certain chemical fragrances just…

Addictionary

The verb pink referring to perforation and piercing is from a Middle English word meaning “to thrust.” It dates back to the beginning of the 16th century, while the name refers to the color pink date…