Compose and andThen methods

Well, this:

addUhum _

is an eta expansion. It converts methods into functions. On the other hand, this:

addUhum(_)

is an anonymous function. In fact, it is a partial function application, in that this parameter is not applied, and the whole thing converted into a function. It expands to:

x => addUhum(x)

The exact rules for expansion are a bit difficult to explain, but, basically, the function will “start” at the innermost expression delimiter. The exception is partial function applications, where the “x” is moved outside the function — if _ is used in place of a parameter.

Anyway, this is how it expands:

val ummThenAhem = x => addAhem(x).compose(y => addUmm(y))

Alas, the type inferencer doesn’t know the type of x or y. If you wish, you can see exactly what it tried using the parameter -Ytyper-debug.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)