Last active
September 21, 2017 04:56
-
-
Save Atternatt/91e63b86a98f886f58fe686f6a911b45 to your computer and use it in GitHub Desktop.
Functionalize!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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