natefaubion / purescript-run

An extensible-effects implementation
MIT License
158 stars 14 forks source link

Run multiple readers at once by providing a record #28

Open paluh opened 4 years ago

paluh commented 4 years ago

I have this ugly prototype for runReaders: https://try.purescript.org/?gist=7fe346867c14d18e78ff06e32673ae5f . I wonder if something like this (with a better API of course) could be included in this lib. What do you think? Any ideas how to make this better - should I stick with onMatch and transform only input record?

(Ping @3ddyy - I've seen that you have improved reader API recently ;-))

artemisSystem commented 4 years ago

That sounds like a good idea to me. The only thing i really learned about reader from working with it is that it's tricky 😝. I was also trying to implement a local so that the type for the read value could be different, but couldn't get it to work

paluh commented 4 years ago

@3ddyy I've updated the gist. I've added simple record mapping which prepares a given record of values for internal onMatch call. I'm not sure if the implementation is readable enough and worth a PR. I allowed myself to use inefficient Record.insert to preserve some simplicity because I hope that this record transformation is done only once during the whole interpretation. What do you think?

paluh commented 4 years ago

P.S. I think that something similar could be done for effect handlers like runStateAt or catchAt too.