Notes from the journey as a software dev

Main menu

Post navigation

A week or so ago I’ve contributed in StackOverflow Documentation an entry about Currying under the Scala Language tag. I’ve repeated the same exercise for Java Currying Documentation. This is how it goes:

Curryingis the technique of translating the evaluation of a function that takes multiple arguments into evaluating a sequence of functions, each with a single argument.

This is normally useful when for example:

different arguments of a function are calculatedat different times.(Example 1)

different arguments of a function are calculatedby different tiers of the application.(Example 2)

Example 1

Let’s assume that the total yearly income is a function composed by the income and a bonus:

val totalYearlyIncome😦Int,Int)=>Int=(income, bonus)=> income + bonus

The curried version of the above 2-arity function is:

val totalYearlyIncomeCurried:Int=>Int=>Int= totalYearlyIncome.curried

Note in the above definition that the type can be also viewed/written as:

A week or so ago I’ve contributed in the StackOverflow Documentation an entry about Currying which until now it’s mostly intact and only cosmetic changes have been made to the original. This is how it goes:

Curryingis the technique of translating the evaluation of a function that takes multiple arguments into evaluating a sequence of functions, each with a single argument.

This can be useful when:

Different arguments of a function are calculated at different times. (see Example 1)

Different arguments of a function are calculated by different tiers of the application. (see Example 2)

As is the case with any new framework (or major addition to an existing and well known framework) the best way to approach it, work with it and learn it is not to dive head first but rather take baby steps in areas that feel more accessible and can link with ideas/processes/steps you are already following.

Spring Boot is sporting several starter recipes that can speedup your configuration and can be consumed separately to each other.

Let’s first talk about logging.

The best practise is to code against SLF4J, provide a desired implementation (preferably Logback), and include in the classpath SLF4J bridges for JUL, JCL and Log4J.

The process is described here by the person/team that authored SLF4J, Log4J, Log4j2, Logback and all the 3 SLF4J bridges namely for JUL, JCL, and Log4J.

The design we described and we are aiming at is also well depicted in the link above and is provided here for quick reference:

Let’s say we want to find all three-pair additions that equate to 10 (order is irrelevant so we don’t want dups). What we would normally do in imperative Java would be 3 nested for loops with indexes say i, j and k where i ranges from 1 till 10, j starts from i+1 and k starts from j+1. The body of the for loop would be the if predicate case. We would also need a variable to store the results.

Timing method operations can be a labouring task littering the method body with the timing variables (sometimes short-lived as in debug mode). Thankfully we can treat the timing activity as a pass-by-name method argument of our newly defined timing operation: