Is there any way to create generator functions in ...
# javascript
c
Is there any way to create generator functions in Kotlin JS ?
p
c
I saw that, but I figured it was only usable for lists. But it raises a second question, if I'm trying to build a project with Kotlin-JS does it refrain me from using the entire stdlib? (would using kotlin stdlib instead of kotlin-js compromise the claim that it's a kotlin-JS project?)
p
there is no kotlin-js without the stdlib
c
Alright, I'll give it a try then, thanks!
Alright, I think it's fair to say that when someone says they're using kotlin js it's the stdlib-js which is a package within the stdlib. But using the stdlib would imply using all the packages which also include jvm and native etc. https://kotlinlang.org/api/latest/jvm/stdlib/index.html so, coming back to my point is that sequences and yields are outside the kotlin js package (stdlib-js).
when we chose to compile kotlin to javascript we will also get the js flavour of kotlin. All of the common stdlib functions are available on the js platform along with some additional, platform-secific ones (e.g.
JSON
object). There is no way we can use a jvm or native function on the js platform.
if you browse the stdlib, you will see some colored buttons on the top right which allow you see which functions are available for a specific platform
c
I'm very confused. I'm using gradle and have implemented
kotlin("stdlib-js")
and I won't let me import
kotlin.sequences
to import yield... are you saying that changing the import to
kotlin("stdlib")
will allow me to use yield but it could still be a javascript targeted project (kotlin JS)? Sorry for taking so much of your time.
p
I don’t think you need to import anything at all. The basic project setup with gradle generated by intellij should allow you to just copy & paste the yield example from the docs
c
oh, now I get it, you can only use yield in an sequence object. I'll take a better look at it. Thank you for your time!
Alright so, I'm trying my hand at writing a wrapper for redux-saga, but it requires generator functions in the sagas.
export function* helloSaga() { println("hello saga."); }
My question being, while fairly certain there is not, is there a kotlin function that would generate that javascript generator function code..?