Gozala / reducers

Library for higher-order manipulation of collections
MIT License
181 stars 8 forks source link

Handling errors after end and reduced #34

Closed Raynos closed 11 years ago

Raynos commented 11 years ago

What happens when folder sends reduced back to source.

Gozala commented 11 years ago

At the moment any transformation (each is build using reducible) will ignore anything send after end or reduced and will return reduced back to attempt to close down a source again.

Gozala commented 11 years ago

The reason why this is not all strictly defined yet is described in #35

Here are some answers on questions that are clear regardless of outcome on above:

  • What happens if a reducible sends error after end?

There are two options here:

  1. Allow only end or error.
  2. Ignore send anything after reduced(value) is returned

Currently implementation works as described in 2., but it maybe worth switching to 1..

  • What happens if it sends data after end.

Data is ignored and same reduced(value) is returned once again. Maybe sending Error("Ended") is a better option ? In terms of API only error or end should be allowed or nothing. If input sends data it's broken and I don't know what should be a strategy for dealing with broken inputs. I choose to normalize by ignoring.

We could probably throw instead and have a normalize function that will normalize broken inputs that are known to throw. Constraint is that throw may occur in specific cases making it hard to track problem while just ignoring would probably kept app working.

I think I prefer some introspection tools that are opt-in and log when inputs are misbehaving.

  • Should end be send by input after reduced(value) is returned ?

Not sure what would make a better option here cons & pros are listed under #35 If you're writing your own reducible you should return end to make sure it will work regardless what we end up deciding.

  • Is it allowed to send error after reduced(value) is returned ?

Answer is same as on previous question. Only reason require send of end is actually to allow sending error.

  • Is it allowed to send data after reduced(value) is returned ?

Absolutely not, such data will be ignored and input sending it will be considered broken having same consequences as sending data after end or error.

It was not listed in the questions here, but error and end are considered as end of input. Difference is that first one ends input with an error and second ends normally.

Gozala commented 11 years ago

Check out Making values reducible guide!