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

Added qualities for delegating functions #83

Merged
merged 1 commit into from
Jul 11, 2023
Merged

Added qualities for delegating functions #83

merged 1 commit into from
Jul 11, 2023

Conversation

orlopau
Copy link
Contributor

@orlopau orlopau commented Jul 5, 2023

No description provided.

* @param delegateResult delegate result, no impact on quality, but must be a valid result that does not cause an excaption
* @param delegateArgumentQuality quality verifying the delegate argument
*/
public DelegateMapsArgument(In outerArgument, Out delegateResult, Quality<DelegateIn> delegateArgumentQuality) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

In general a delegate Qualitys should always be contravariant, i.e. passed as Quality<? super DelegateIn>

* +-----------------------------------------------------------------------------------+
* | DelegateFunction |
* | +------------------------------------------+ |
* | OuterArgument ----> | DelegateArgument -----> DelegateResult | ---> OuterResult |
Copy link
Collaborator

Choose a reason for hiding this comment

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

> needs to be encoded to &gt;

@codecov-commenter
Copy link

Codecov Report

Patch coverage: 100.00% and project coverage change: -0.03 ⚠️

Comparison is base (ace50eb) 96.94% compared to head (6dc0267) 96.91%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

Additional details and impacted files
@@             Coverage Diff              @@
##               main      #83      +/-   ##
============================================
- Coverage     96.94%   96.91%   -0.03%     
- Complexity      598      606       +8     
============================================
  Files           156      158       +2     
  Lines          1308     1330      +22     
  Branches         46       46              
============================================
+ Hits           1268     1289      +21     
- Misses           34       35       +1     
  Partials          6        6              
Impacted Files Coverage Δ
...fidence/quality/function/DelegateMapsArgument.java 100.00% <100.00%> (ø)
...onfidence/quality/function/DelegateWithResult.java 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

* @param delegateResult delegate result, no impact on quality, but must be a valid result that does not cause an excaption
* @param delegateArgumentQuality quality verifying the delegate argument
*/
public MapsArgument(In outerArgument, Out delegateResult, Quality<DelegateIn> delegateArgumentQuality) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

the delegateArgumentQuality argument should also be of type Quality<? super DelegateIn>, not just the member ;-)

final AtomicReference<DelegateIn> delegateValueReference = new AtomicReference<>();
final Function<In, Out> actualFunction = candidate.apply(delegateValue -> {
delegateValueReference.set(delegateValue);
return mDelegateResult;
Copy link
Collaborator

Choose a reason for hiding this comment

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

let's take the shortcut here and throw a custom Error. Having to provide a return value makes this more cumbersome.

return mDelegateResult;
});

actualFunction.apply(mOuterArgument);
Copy link
Collaborator

@dmfs dmfs Jul 7, 2023

Choose a reason for hiding this comment

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

What happens when the outer function doesn't call the delegate at all? I'd like to see this covered by the Quality.

*/
public MapsArgument(In outerArgument, Quality<? super DelegateIn> delegateArgumentQuality)
{
this.mOuterArgument = outerArgument;
Copy link
Contributor Author

@orlopau orlopau Jul 11, 2023

Choose a reason for hiding this comment

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

Remove this., and remove @param annotations

* | +------------------------------------------+ |
* | OuterArgument ----&gt; | DelegateArgument -----&gt; DelegateResult | ---&gt; OuterResult |
* | +------------------------------------------+ |
* +-----------------------------------------------------------------------------------+
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Add example

private final Out mDelegateResult;
private final Quality<? super Function<In, Out>> mDelegate;

public ResultOf(Out delegateResult, Quality<Function<In, Out>> delegate)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Add ...super...

@dmfs dmfs merged commit 3d8cef3 into saynotobugsorg:main Jul 11, 2023
1 check passed
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

Successfully merging this pull request may close these issues.

3 participants