Python generators equivalent?

Well, at least for Enum.split/2s strictness there has been a discussion recently:

This also tackles some small bits of your “state” problem.

In elixir I do usually not expect side effects to happen, so next(s) which returns 1 on the first call and 2 on the second without rebinding s would be counterintuitive for me.

If you need a central authority handing out free ids, work items, whatever, I do think that is what GenStage has been developed for.

If you really need something as your python thingy (which involves far too much magic for me, I’d expect it to loop forever) then you need to implement it yourself. Some protocol or behaviour and a handfull of macros, and you are ready to release it on hex.

1 Like