block by nicerobot 4968883

Hmm, personally, what's needed is for compilers to provide nice graphs of the structure of the code.

Let’s say i want to apply functions a, b, c, and d to each element of a list, xs, such that the result of a is passed to b who’s result is passed to c who’s result is passed to d. It’s:

xs.map(a).map(b).map(c).map(d)

or

xs.map(d(c(b(a(_)))))

To me, that’s clear (assuming the naming is clearly defined), but it probably doesn’t read well since, at least in english, we read left to right, not inside-out (nor right to left).

It might be nicer to define a function something like:

(x) => a(x) -> b -> c -> d

So, in Scala:

val fs = List(a _, b _, c _, d _)

then just comose them:

val fc = d _ compose c _ compose b _ compose a _

Now you have a function that’ll apply d(c(b(a(_)))) and is usable in a map:

xs.map(fc)

compose.scala

function.composer.scala

graph.compose.clj