Got a suggestion to create a cheat sheet showing h...
# datascience
t
Got a suggestion to create a cheat sheet showing how to convert math symbols and expressions into Kotlin code. Here's the start, contributions welcome. https://github.com/thomasnield/kotlin_math_cheatsheet/blob/master/README.md
👍 10
❤️ 1
o
e
Math.pow(x, 2.0)
->
x.pow(2)
👍 2
Nested sums look much closer to math using builder notation:
(1..4).flatMap { i -> (4..20).map { j -> 2 * i * j } }.sum()
->
sequence { for(i in 1..4) for (j in 4..20) yield(2 * i * j) }.sum()
Btw, somewhere around 1.4 (when we have new type inference) we can offer an even better (and much faster) version of “sum builder” in stdlib:
Copy code
sum { for(i in 1..4) for (j in 4..20) add(2 * i * j) }
t
@elizarov Cool, it looks similar to Python comprehensions without the weird backwardness. This would be awesome to have as well as improving range and progressions for continuous numeric types. https://github.com/Kotlin/KEEP/pull/137
Putting those improvements into the sheet.
h
@elizarov Are there some docs/teaser already about how type inference is going to change in 1.4?
e
Nothing is definite yet. We hope that inference is going to smart enough, so that we can overload by return type of lambda….
t
@elizarov that would be amazing