rx icon indicating copy to clipboard operation
rx copied to clipboard

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

Open Robert-M-Muench opened this issue 5 years ago • 1 comments

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.

Robert-M-Muench avatar Jun 16 '19 16:06 Robert-M-Muench

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.

lempiji avatar Jan 02 '20 13:01 lempiji