hive icon indicating copy to clipboard operation
hive copied to clipboard

returns library

Open robfitzgerald opened this issue 4 years ago • 3 comments

throughout hive, especially in the VehicleState FSM, there are methods with the following signature:

Tuple[Tuple[Exception], Tuple[T]]

where T may be SimulationState, or, some kind of vehicle state, or others. this describes a method which can fail, do nothing, or possibly return a T, and we allow these instances:

error, None  # experienced an error
None, t      # result of method, no error
None, None   # method fails without an error

where the combination "error and a result t" is disallowed.

this is based off the idea of the error-first callback in Node.js, but, also simulates a low-tech version of the Either monad from Scala. the Returns library also has it's implementation of this, with the Result and ResultE types.

Result would reduce our signatures from Tuple[Tuple[Exception], Tuple[T]] to ResultE[T], but, it also brings a lot more with it, some of which may be awkward to integrate into our code base. do we consider using Result?

alternatively a low-tech solution (which doesn't protect us as well from dev errors): should we simply add a type alias for Tuple[Tuple[Exception], Tuple[T]]:

T = TypeVar('T')
Result[T] = Tuple[Tuple[Exception], Tuple[T]]

robfitzgerald avatar May 06 '21 21:05 robfitzgerald

Another overlapping issue: #84

nreinicke avatar Jan 27 '22 21:01 nreinicke

We should probably merge this with #84 and possibly break out into sub issues

nreinicke avatar Apr 04 '23 20:04 nreinicke

Also make sure we deal with cases where the simulation state is None appropriately.

nreinicke avatar Apr 04 '23 20:04 nreinicke