Open Overbryd opened 6 years ago
Using the reader/writer modules is pretty useful. Not only Maps could be used, but also other protocols, like Lists, individual structs, ... Also, one could build a reader to pass a static or configuration value to a stage and just add the response to the state.
I like the idea of making it a Pipette feature that deals with the value before it actually reaches the handling GenStage. What do you think of combining it like this?
@state read: {AccessReader, from: [:foo, :bar]}, write: {AccessWriter, into: [:foo, :baz]}, stage: %Pipette.Stage{handler: {API, :get}}
We could provide a config to define a default reader and writer. Also, in order to have a better separation between the stage definition and the stage options, we could change it to be parameters and options:
@stage :name, %Pipette.Stage{handler: {API, :get}}, read: {AccessReader, from: [:foo, :bar]}, write: {AccessWriter, into: [:foo, :baz]}
Very often, values are not being transformed in a linear fashion, but more taken from/append to a state map.
So it seems to be common to start out with a value, then build up state with different keys on each stage. Each stage in a network could be used to take input values from a specified key of the map and its return values from a specific output label would be written back to a specified key.
Proposals: