Bruno
01/24/2020, 9:20 PM[1..10]
|> List.map (add 2)
|> List.map (mult 3)
My attempts:
#1
(1..10)
.pipe { it.map { add(2) } }
.pipe { it.map { mult(3) } }
#2
(1..10)
.map { add(2) }
.map { mult(3) }
What am I missing?
I'd expect a list like:
[9,12,15,18,21,24,27,30,33,36]
, but instead get a List<(Int) -> Int>
Bob Glamm
01/24/2020, 9:24 PMval add(x) = { it + x }
or the like?Bruno
01/24/2020, 9:25 PMval add = { x: Int, y: Int -> x + y }
Bob Glamm
01/24/2020, 9:26 PM.map(add(2))
Bob Glamm
01/24/2020, 9:27 PM{ add(2) }
is a function that returns the partially applied add
function, although it surprises me that Kotlin automatically curried it for youBob Glamm
01/24/2020, 9:27 PM{ add(2) }
is equivalent to { it -> add(2) }
so it just maps the integer to the partially-applied functionsimon.vergauwen
01/24/2020, 9:28 PM(0..10).map { it + 2 }.map { it * 3 }
or (0..10).toList()…
simon.vergauwen
01/24/2020, 9:28 PMsimon.vergauwen
01/24/2020, 9:29 PM(1..10)
.map(add(2))
.map(mult(3))
is what you want heresimon.vergauwen
01/24/2020, 9:30 PMsimon.vergauwen
01/24/2020, 9:30 PMsimon.vergauwen
01/24/2020, 9:30 PMBruno
01/24/2020, 9:31 PM