Created
March 13, 2020 14:11
-
-
Save surajsau/1019b1f0c72cd1e41c54b13a38bc3b4c to your computer and use it in GitHub Desktop.
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
// All return a type Monad | |
val split: (String) -> Monad<Pair<StringPair, StringPair>> = { str -> | |
.. | |
Monad.Something(Pair(..)) | |
} | |
val convertToInt: (pair: Pair<StringPair, StringPair>) -> Monad<Pair<IntPair, IntPair>> = { pair -> | |
.. | |
Monad.Something(Pair(..)) | |
} | |
val transform: (pair: Pair<IntPair, IntPair>) -> Monad<Int> = { pair -> | |
.. | |
Monad.Something(Int) | |
} | |
val test = "10,2,3,1" | |
val result = Monad.Something(test) // Monad("10,2,3,1") | |
.flatMap(split) // Monad((("10", "2"), ("3", "1"))) | |
.flatMap(convertToInt) // Monad(((10, 2), (3, 1))) | |
.flatMap(transform) // Monad(3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment