Skip to content

Instantly share code, notes, and snippets.

@Atternatt
Last active September 21, 2017 04:56
Show Gist options
  • Save Atternatt/91e63b86a98f886f58fe686f6a911b45 to your computer and use it in GitHub Desktop.
Save Atternatt/91e63b86a98f886f58fe686f6a911b45 to your computer and use it in GitHub Desktop.
Functionalize!
fun twice(int: Int) = int * 2
fun trice(int: Int) = int * 3
fun getString(int: Int) = int.toString()
//el operador rangeTo es el '..' acepta un parametro de entrada y otro de salida
//si usamos mónadas para enlazarlo podemos concatenar la salida de uno con la entrada del otro
operator fun <T,R,V> ((T)->R).rangeTo(other: ((R)->V)): ((T)->V){
return {
other(this(it))
}
}
fun composed(value: Int) = (::trice..::twice..::getString)(value)
//es lo mismo que
getString(twixe(trice(10)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment