concept parameter in category functional programming

appears as: parameter, parameters, parameter, parameters
Grokking Functional Programming MEAP V11

This is an excerpt from Manning's book Grokking Functional Programming MEAP V11.

So the final implementation could look like this:

We don’t have to use Comparator as an argument. The main functionality that we want to pass to the rankedWords function is “a way to calculate score for a given word”. This is the only thing that has changed in our code because of the business requirements and therefore it should be the only customizable thing. We achieve customization using parameters.

def rankedWords(wordScore: String => Int,
                words: List[String]): List[String] = {
  words.sortBy(wordScore).reverse
}
def score(word: String): Int = word.replaceAll("a", "").length
def bonus(word: String): Int = if (word.contains("c")) 5 else 0

As you can see, it’s been pretty straightforward until now. We have been just passing functions to the sortBy function, but it won’t do this time. Can we implement this new feature in the same concise and readable way? Yes, we can, this and many more features that come next!

Functional Programming with Kotlin MEAP V07

This is an excerpt from Manning's book Functional Programming with Kotlin MEAP V07.

It’s a common convention to use names like f, g, and h for parameters to a higher-order function. In functional programming, we tend to use very short variable names, even one-letter names. This is usually because HOFs are so general that they have no opinion on what the argument should actually do. All they know about the argument is its type. Many functional programmers feel that short names make code easier to read, since it makes the structure of the code easier to see at a glance.

Functional Programming in JavaScript

This is an excerpt from Manning's book Functional Programming in JavaScript.

An improvement, indeed, but still not a completely reusable piece of code. Suppose you want to write to a file instead of an HTML page. You need to take the simple thought process of creating parameterized functions to a different level, where parameters aren’t just scalar values but can also be functions themselves that provide additional functionality. Functional programming is a bit like using functions on steroids, because your sole objective is to evaluate and combine lots of functions with others to achieve greater behavior. I’ll fast-forward a bit and show you a sneak peek at this same program using a functional approach.

On the other hand, a curried function is one where all arguments have been explicitly defined so that, when called with a subset of the arguments, it returns a new function that waits for the rest of the parameters to be supplied before running. Figure 4.6 represents this visually.

Figure 7.4. With currying, each parameter of the curried function is internally transformed to a nested call. This flexibility of being able to supply parameters sequentially has the downside of occupying additional stack frames.
Functional Programming in Java: How functional techniques improve your Java programs

This is an excerpt from Manning's book Functional Programming in Java: How functional techniques improve your Java programs.

If you need more information about the types, you can simply write them in front of each lambda parameter, enclosing the type and the parameter between parentheses:

The processElement method also used specific data in the form of the element names, which correspond to the parameters of the format string used to display them. You can replace the format parameter with a Tuple of the format string and a list of parameters. This way, the processElement method will become the following:

15.3.6. Making the element-processing function a parameter

The two remaining problems can be solved with a single change: passing the element-processing function as a parameter to the readXmlFile method. This way, this method will have a single task: read the list of first-level elements in the file, apply them to a configurable function, and return the result. The main difference is that the method will no longer produce a list of strings and apply a string effect.

sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest