Generator functions and Redux Saga

Hello, how can I use redux-saga with ReScript? And can I able to do that?
If not, do you want to support this?

1 Like

There is no syntax (afaia) for generators in ReScript. I think there was discussions around adding syntax for it, connected with async/await syntax - would be good for someone who has more context to chime in here.

As with async/await where you can use rescript Promise bindings, you can do similar things with generators - although there may be less prior art in this space. The core idea is that you can build a generator through functional composition and offer a function that converts that to a JS generator ie. an object with next(), return(), and throw() methods.

Thanks, could you give me example, how can I use generators right now?
I think it’s difficult, only with “raw” I suppose

It should be relatively simple, just playing around though I’m not sure how to implement the iterarable protocol. I’ve spun this off into a separate question: Implementing the iterable protocol (Symbol.iterator)

1 Like

There never have been any discussions on generators, so it’s very unlikely they will be supported on a compiler / syntax level any time soon.

Why not? I can suppose that it does not fit into ideology FP.

Generator syntax shares a lot of semantics with async/await, especially when generalised in a system with algabreic effects. I assumed that work done on async/await would have cross cutting benefits for potential generator syntax.

1 Like

From the docs: Async & Promise | ReScript Language Manual

it is planned for us to introduce a coroutine-like feature in the future; for that reason, we’re postponing introducing the keywords async and await into the language

Thanks for reminding me. We initially thought that we’d be able to introduce some coroutine-like runtime in the standard library, but it turned out that this was a misunderstanding within the team.

I updated the docs to reflect the current state.

This has nothing to do with FP. We just have to prioritise what to work on next, and generators are very low priority right now. You can check out our roadmap to get a better feeling on what we are working on.

1 Like