-
-
Save albodelu/06e76f30ebd9b760c8ab0bfc05104a96 to your computer and use it in GitHub Desktop.
Functionalize!
This file contains hidden or 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