Reverse
Reverse takes any function and returns it with its parameter in the reverse order (in other languages, this function is known as flip). Let's look at the following code:
import arrow.syntax.function.partially3 import arrow.syntax.function.reverse fun main(args: Array<String>) { val strong: (String, String, String) -> String = { body, id, style -> "<strong id=\"$id\" style=\"$style\">$body</strong>" } val redStrong: (String, String) -> String = strong.partially3("font: red") //Explicit println(redStrong("Red Sonja", "movie1")) println(redStrong.reverse()("movie2", "The Hunt for Red October")) }
Our redStrong
function is awkward to use, as we'll expect to have id
first and then body
, but, is easily fixable with the reverse
extension function. The reverse
function can be applied to functions from parameters 1
to 22
.