i'm playing around with map in kotlin, and currently I would like to see whether it would be possible to map a list of integers to a list of functions (Int) -> Int, while doing a bunch of operations inside the lambda that would require me to save values to vals
So I have this simple code:
val num = arrayOf(1, 2, 3, 4)
val funcs = num.map <Int, (Int) -> Int > { x -> {
y -> y + x
}}
This is a bit of a condensed example, the thing i'm really trying to do is a bit more convoluted. But I need to quite a bit of operations inside of of the 'inner' lambda, so I need to write codeblocks where I can use val. Like this:
val fs = num.map <Int, (Int) -> Int > { x -> {
y -> {
val tmp = y *2
val tmp1 = x / 2
tmp + tmp1
}
}}
But this part doesnt work, the compiler is confused by return types How can I do something like this?
y -> y * 2 + x / 2?