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

Binary #825

Closed
Vatavuk opened this issue May 7, 2018 · 16 comments
Closed

Binary #825

Vatavuk opened this issue May 7, 2018 · 16 comments

Comments

@Vatavuk
Copy link
Contributor

Vatavuk commented May 7, 2018

We currently have Ternary which is equivalent to if then else.
I propose to create Binary that would be equivalent to if then for
situations when a user needs to execute a specific action for given condition.

Binary should:
- implement Scalar<Boolean>
- provide two ctors: (Scalar<Boolean> condition, Scalar<T> scalar) and (Scalar<Boolean> condition, Runnable runnable)
- return true if condition is met and action is triggered

@0crat
Copy link
Collaborator

0crat commented May 7, 2018

@llorllale/z please, pay attention to this issue

@llorllale
Copy link
Contributor

@Vatavuk seems like overkill to me. Why not simple if(...){...} ?

@llorllale
Copy link
Contributor

@Vatavuk btw, I believe you can currently do something similar using And

@Vatavuk
Copy link
Contributor Author

Vatavuk commented May 11, 2018

@llorllale I don't see how can we do this with And.
My reasoning is following:
I am looking at cactoos as a layer above java that provide us pure OOP approach. No if,else,for,while,try/catch... statements, nothing but objects. I'm currently working on a cactoos powered project with nothing but objects (few thousand lines so far) and this really started to look like a different language. Very close to EO language. But this argument is mainly subjective.

Although, one if statement is probably overkill I think it would be useful for multiple conditional statements.
One concrete example I can think of is if elseif statments. When we don't want to execute second
conditional test if we don't need to:

if (condition1.test()) {
   action1.trigger();  
}
else if(condition2.test()) {
   action2.trigger();
}

This can be rewritten using Or and Binary combo:

new Or(
   new Binary(() -> condition1.test(), () -> action1.trigger()),
   new Binary(() -> condition2.test(), () -> action2.trigger())
).value();

@llorllale
Copy link
Contributor

@Vatavuk one of the ctors you proposed was (Scalar<Boolean> condition, Scalar<T> scalar). How does that fit with what you're trying to achieve?

@Vatavuk
Copy link
Contributor Author

Vatavuk commented May 11, 2018

@llorllale just to provide more usage options, the result of Scalar<T> scalar will be ignored

@llorllale
Copy link
Contributor

@Vatavuk I don't see a reason to provide that ctor with scalar that will be ignored..

Everything else you've said sounds great though.

@Vatavuk
Copy link
Contributor Author

Vatavuk commented May 12, 2018

@llorllale you are right, we can drop that ctor. I thought I have an example of such a usage but nothing rational comes in to my mind.

@Vatavuk
Copy link
Contributor Author

Vatavuk commented May 17, 2018

@llorllale I remembered now, we need scalar in ctor if we want to throw checked exceptions.
For instance:

new Binary(
   condition,
   () -> {throw new IOException(msg);}
)

@llorllale
Copy link
Contributor

@0crat in

@0crat
Copy link
Collaborator

0crat commented May 22, 2018

@0crat in (here)

@llorllale Job #825 is now in scope, role is DEV

@0crat
Copy link
Collaborator

0crat commented May 22, 2018

Bug was reported, see §29: +15 point(s) just awarded to @Vatavuk/z

@0crat
Copy link
Collaborator

0crat commented Jan 29, 2019

The job #825 assigned to @borysfan/z, here is why; the budget is 30 minutes, see §4; please, read §8 and §9; if the task is not clear, read this and this; there will be no monetary reward for this job

borysfan added a commit to borysfan/cactoos that referenced this issue Jan 29, 2019
borysfan added a commit to borysfan/cactoos that referenced this issue Jan 30, 2019
borysfan added a commit to borysfan/cactoos that referenced this issue Feb 4, 2019
borysfan added a commit to borysfan/cactoos that referenced this issue Feb 4, 2019
borysfan added a commit to borysfan/cactoos that referenced this issue Feb 5, 2019
borysfan added a commit to borysfan/cactoos that referenced this issue Feb 11, 2019
borysfan added a commit to borysfan/cactoos that referenced this issue Feb 11, 2019
@borysfan
Copy link
Contributor

borysfan commented Feb 20, 2019

@llorllale Hey. This issue has been covered in PR #1054. Could you please close this issue?

@Vatavuk Vatavuk closed this as completed Feb 20, 2019
@0crat 0crat removed the scope label Feb 20, 2019
@0crat
Copy link
Collaborator

0crat commented Feb 20, 2019

The job #825 is now out of scope

@0crat
Copy link
Collaborator

0crat commented Feb 20, 2019

Order was finished: +30 point(s) just awarded to @borysfan/z

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

No branches or pull requests

4 participants