Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Robert-M-Muench opened this issue Jun 16, 2019 · 1 comment
Open

Comments

@Robert-M-Muench
Copy link

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
Copy link
Owner

lempiji commented Jan 2, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants