Nezteb
04/23/2019, 7:31 PMval myArg = 1
val myFuncs = listOf(::addOne, ::addTwo, ::addThree)
myArg.someCoolMapFunctions(myFuncs)
There’s a stack overflow answer for Haskell to define this function yourself, but I don’t know what the equivalent Kotlin code would be https://stackoverflow.com/a/47501940/7682196streetsofboston
04/23/2019, 7:32 PMsomeCoolMapFunctions be?Nezteb
04/23/2019, 7:33 PMListType<myArg> I would thinkstreetsofboston
04/23/2019, 7:33 PMList<Int>? or List<() -> Int>Nezteb
04/23/2019, 7:34 PMList<Int> in this caseNezteb
04/23/2019, 7:35 PMval listOfOutputs = listOf<Int>()
for(func in myFuncs) {
listOfOutputs += func(myArg)
}streetsofboston
04/23/2019, 7:36 PMfun Int.someCoolMapFunctions(list: List<(Int)->Int>) : List<Int> = list.map { it(this) }streetsofboston
04/23/2019, 7:38 PMList<() -> Int> (a list of deferred results instead of a list of results):
fun Int.someCoolMapFunctions(list: List<(Int) -> Int>) : List<() -> Int> = list.map { { it(this) } }Ruckus
04/23/2019, 7:44 PMval outputs = myFuncs.map { it(myArg) }
is pretty concise.Nezteb
04/23/2019, 7:46 PMmap. Thanks!