Skip to content

#677 add pattern Trampoline. #696

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

Merged
merged 5 commits into from
Feb 25, 2018
Merged

#677 add pattern Trampoline. #696

merged 5 commits into from
Feb 25, 2018

Conversation

besok
Copy link
Contributor

@besok besok commented Jan 8, 2018

Pull request title

Pull request description

  • Add readme, code,test.

For detailed contributing instructions see https://github.com/iluwatar/java-design-patterns/wiki/01.-How-to-contribute

@besok
Copy link
Contributor Author

besok commented Jan 8, 2018

Throttling test has failed.
I don't understand what i should do now.

@iluwatar
Copy link
Owner

It is a known issue #643

Copy link
Owner

@iluwatar iluwatar left a comment

Choose a reason for hiding this comment

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

  • The project is missing from parent pom.xml
  • The module build fails with Checkstyle errors

it is possible to implement algorithms recursively in Java without blowing the stack
and to interleave the execution of functions without hard coding them together or even using threads.


Copy link
Owner

Choose a reason for hiding this comment

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

Would it be possible to explain the pattern shortly in Explanation section? See https://github.com/iluwatar/java-design-patterns/wiki/02.-Pattern-template and some other patterns like http://java-design-patterns.com/patterns/decorator/ for examples.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i added section,

* [Trampolining: a practical guide for awesome Java Developers](https://medium.com/@johnmcclean/trampolining-a-practical-guide-for-awesome-java-developers-4b657d9c3076)
* [Trampoline in java ](http://mindprod.com/jgloss/trampoline.html)
* [cyclops-react](https://github.com/aol/cyclops-react)

Copy link
Owner

Choose a reason for hiding this comment

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

Use Tutorials section for examples. Pattern descriptions can be in Credits.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed it.

<version>1.16.18</version>
<scope>provided</scope>
</dependency>

Copy link
Owner

Choose a reason for hiding this comment

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

Using Lombok should be project level decision. We haven't used it elsewhere so please do not take it into use in one pattern.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

the key enabling mechanism is the fact that Trampoline.more is a lazy operation.
Trampoline in cyclops-react extends java.util.Supplier. Calling Trampoline.more we are basically creating
a Supplier that defers the actual recursive call, and having defered the call we can move it outside of the recursive loop.
This means we can define algorithms recursively in Java but execute them iteratively.*/
Copy link
Owner

Choose a reason for hiding this comment

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

Please refer to methods properly in Javadoc e.g. {@link package.class#member label}. What is cyclops-react?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cyclops-react is a library for additions java8 streams.
done.

Trampoline in cyclops-react extends java.util.Supplier. Calling Trampoline.more we are basically creating
a Supplier that defers the actual recursive call, and having defered the call we can move it outside of the recursive loop.
This means we can define algorithms recursively in Java but execute them iteratively.
*/
Copy link
Owner

Choose a reason for hiding this comment

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

Please prefer <p> tag in Javadoc. See other patterns for examples. Please describe what the example does and how it implements the pattern.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

public class TrampolineAppTest {

@Test
public void test()throws IOException{
Copy link
Owner

Choose a reason for hiding this comment

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

Please use descriptive test method name? What does it test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Changed to testTrampolineWithFactorialFunction

@iluwatar
Copy link
Owner

@besok please comment when you've implemented the changes.

@besok
Copy link
Contributor Author

besok commented Jan 17, 2018

Ok. I am going to do it on holidays(20-21.01)

@besok
Copy link
Contributor Author

besok commented Jan 20, 2018

The project is missing from parent pom.xml

How can i add this modula to parent pom?
I added record to module section in parent pom.

@besok
Copy link
Contributor Author

besok commented Feb 1, 2018

@iluwatar , can you check my changes?

@iluwatar iluwatar merged commit 7fef5e4 into iluwatar:master Feb 25, 2018
@iluwatar
Copy link
Owner

Well done @besok 👍 Thanks for the new pattern!

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.

2 participants