Anyone know how to achieve kotlin-like `inline` be...
# random
y
Anyone know how to achieve kotlin-like
inline
behaviour in Scala? Does something like this just work?
Copy code
inline def forEach(inline block: Int => Unit): Unit
With
block
getting mentioned only once inside
y
I mean the other way around. I want to write efficient
map
s for instance in Scala, or a for-each, but without a closure actually being creates
e
assert
is hard-wired in the compiler to be lazy in its argument but otherwise there isn't
why though?
oh wait you're asking a different question than I thought
1
y
Mostly as an academic exercise. I want to use such code while still being able to argue that it's efficient enough.
inline
gives me that in Kotlin, so I'm hoping that there's an equivalent in Scala, and figured if anyone would know it would be people here
y
Yeah so would the following code do the trick, or do I need some complicated
Quotes
stuff?
Copy code
inline def forEach(inline block: Int => Unit): Unit
Also I'm guessing there's no nice (and performant) way to do non-local returns, so I would likely need to have
block
return whether to keep iterating or not
e
yeah I'm not sure from their docs
k
assert
is hard-wired in the compiler to be lazy in its argument
That's only in Java, not in Kotlin.
k
That's strange, I'm using 1.9.22 and the following prints "AB":
Copy code
fun main(args: Array<String>) {
    assert(false.also { print("A") } )
    println("B")
}
e
ah,
-Xassertions=jvm
isn't default, but it is the default (only) behavior on native and js
thank you color 1