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

#1445: Reorganise classes around Scalar and Callable #1494

Closed
wants to merge 8 commits into from

Conversation

fabriciofx
Copy link
Contributor

Per #1445 :

  • Improve ScalarOf
  • Rename RepeatedCallable to Repeated
  • Remove ScalarOfCallable
  • Remove CallableOf

@codecov-io
Copy link

codecov-io commented Nov 1, 2020

Codecov Report

Merging #1494 into master will decrease coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #1494      +/-   ##
============================================
- Coverage     89.38%   89.36%   -0.03%     
+ Complexity     1630     1628       -2     
============================================
  Files           279      277       -2     
  Lines          3909     3911       +2     
  Branches        211      211              
============================================
+ Hits           3494     3495       +1     
- Misses          382      384       +2     
+ Partials         33       32       -1     
Impacted Files Coverage Δ Complexity Δ
...rc/main/java/org/cactoos/experimental/Threads.java 100.00% <100.00%> (ø) 8.00 <1.00> (+1.00)
src/main/java/org/cactoos/experimental/Timed.java 100.00% <100.00%> (ø) 9.00 <1.00> (+1.00)
src/main/java/org/cactoos/func/BiFuncOf.java 90.90% <100.00%> (-9.10%) 10.00 <1.00> (-1.00)
src/main/java/org/cactoos/scalar/Repeated.java 100.00% <100.00%> (ø) 2.00 <2.00> (?)
src/main/java/org/cactoos/scalar/ScalarOf.java 100.00% <100.00%> (ø) 5.00 <5.00> (+3.00)
src/main/java/org/cactoos/scalar/Sealed.java 100.00% <0.00%> (ø) 2.00% <0.00%> (ø%)
src/main/java/org/cactoos/iterator/TailOf.java 100.00% <0.00%> (ø) 1.00% <0.00%> (ø%)
...in/java/org/cactoos/scalar/ScalarWithFallback.java 100.00% <0.00%> (ø) 10.00% <0.00%> (ø%)
src/main/java/org/cactoos/iterable/IterableOf.java 96.42% <0.00%> (+0.13%) 17.00% <0.00%> (ø%)
... and 5 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a8e0dab...96f391b. Read the comment docs.

*/
public ScalarOf(final Scalar<T> origin) {
this.origin = origin;
public ScalarOf(final Func<X, T> fnc, final X ipt) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fabriciofx Func & Proc parameters should follow PECS (not sure about `Scalar``).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andreoss done!

return new Repeated<>(
new FuncOf<>(this.callable),
public T value() throws Exception {
return new org.cactoos.func.Repeated<>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fabriciofx Can this be moved to the primary ctor?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andreoss done!


/**
* ScalarOf.
*
* @param <X> Element type
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fabriciofx This type parameter should be on ctor level.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andreoss Can you explain it better? Shoul I add X to ctor, as public <X> ScalarOf(final Runnable runnable, final T result)?

Copy link
Contributor

@andreoss andreoss Nov 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fabriciofx Exactly, it should be like that

    public <X> ScalarOf(final Func<? super X, ? extends T> fnc, final X ipt) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andreoss done, and thanks for the help! :)

Copy link
Contributor Author

@fabriciofx fabriciofx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andreoss Please, take a look.

*/
public ScalarOf(final Scalar<T> origin) {
this.origin = origin;
public ScalarOf(final Func<? super X, T> fnc, final X ipt) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fabriciofx Return type should be ? extends T

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andreoss done!

* @since 0.49.2
*/
public final class RepeatedCallable<X> implements Callable<X> {

public final class Repeated<T> implements Scalar<T> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fabriciofx Not realated to the review. But what is the use case for such class?
It seems that it applies some side effects, which is bad for Scalar to have
For example:
new Repeated<>(new Count<>(1), 5)).value() == 6 (all other values lost)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andreoss Sorry, but I didn't get the point. I did some code here to test and works fine (but I can't make Count<T> because, I can't increment something like T:

@Test
void countFiveTimes() throws Exception {
    new Assertion<>(
        "Must repeat count 5 times",
        new Repeated<>(
            new Count(1),
            5
        ),
        new ScalarHasValue<>(5)
    );
}

final class Count implements Scalar<Integer> {
    private AtomicInteger num;

    public Count(final int num) {
        this.num = new AtomicInteger(num);
    }

    @Override
    public Integer value() throws Exception {
        return this.num.incrementAndGet();
    }
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fabriciofx I mean, that with Repeat only the last result is returned, and all of other iteratatios are lost. Which implies mutable state.
So Repeated may be seen as an encouragement to put mutable state in a Scalar, as in your Count example.

@fabriciofx
Copy link
Contributor Author

@andreoss Please, take a new look.

@victornoel
Copy link
Collaborator

@fabriciofx I think we should keep callableof but keep it the simplest as possible (taking a scalar), can you revert that and the changes related? :)

@victornoel
Copy link
Collaborator

@fabriciofx ping :)

@victornoel
Copy link
Collaborator

@fabriciofx can you take a look at the last comments above?

@victornoel
Copy link
Collaborator

@fabriciofx one last call before closing this MR, if you don't plan to tackle it just tell me so that we don't loose more time :)

@victornoel
Copy link
Collaborator

@fabriciofx @andreoss closing this as there are many small problems and I am not getting any feedbacks

@victornoel victornoel closed this Dec 30, 2020
@0crat 0crat added qa and removed 0crat/scope labels Dec 30, 2020
@0crat
Copy link
Collaborator

0crat commented Dec 30, 2020

@sereshqua/z please review this job completed by @andreoss/z, as in §30; the job will be fully closed and all payments will be made when the quality review is completed

@0crat
Copy link
Collaborator

0crat commented Dec 30, 2020

Code review was too long (59 days), architects (@victornoel) were penalized, see §55

@0crat
Copy link
Collaborator

0crat commented Dec 30, 2020

Pull request #1494 was not merged, no payment for ARC, see §28

@sereshqua
Copy link

@0crat quality acceptable

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

Successfully merging this pull request may close these issues.

6 participants