lempiji / rx

Reactive Extensions for D Programming Language
MIT License
53 stars 8 forks source link

Why three different makeObserver(...) functions instead of one? #35

Open Robert-M-Muench opened 5 years ago

Robert-M-Muench commented 5 years ago

There exists:

auto makeObserver(E)(void delegate(E) doPut, void delegate() doCompleted, void delegate(Exception) doFailure)
auto makeObserver(E)(void delegate(E) doPut, void delegate() doCompleted)
auto makeObserver(E)(void delegate(E) doPut, void delegate(Exception) doFailure)

Since every delegate is checked anyway with:

if(_doDelegate !is null)

why not use only one function like this?


auto makeObserver(E)(void delegate(E) doPut, void delegate() doCompleted = null, void delegate(Exception) doFailure = null)

IMO this gives a simpler interface and it allows me to only provide a doPut delegate.

lempiji commented 4 years ago

To take advantage of D's meta-programming strength, most operators perform optimization using "hasCompleted" and "hasFailure." The makeObserver function needs to toggle whether the return value has a "completed" method or a "failure" method, depending on the argument. It is difficult to do this with one function.