-
-
Notifications
You must be signed in to change notification settings - Fork 359
Add Tree Traversal in Emojicode. #471
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
Conversation
@thbwd Thank you very much for the reviews of the Emojicode PRs! 🙂👍 |
📗 | ||
❗️ 🍭 🍇 | ||
↪️ 🐔 children❗️ ▶️ 2 🍇 | ||
↩️↩️ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@thbwd I have one more question tho. While looking through the documentation, I found that I can also return errors.
I think it would be more appropriate to return an error here, if there are more than two children.
How do I use an error type in this method? I think, the documentation doesn't describe, how to provide an error, when you have a method, that returns nothing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not possible by design. An error is either the expected value or an enum.
If you do not have a return type, there would not be an non-error type. Therefore we have either an enum indicating an error or no value at all, which is clearly what optionals are designed for.
This is also how the file package handles it:
https://www.emojicode.org/docs/packages/files/1f4c4.html#cm📻❗%EF%B8%8F
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, would the following be a correct implemetation?
Declare an enum to hold an error value:
🦃 ⏹ 🍇
🔘 ⏫
❗️ 🔡 ➡️ 🔡 🍇
↪️ 🐕 🙌 🆕⏹⏫❗️ 🍇
↩️ 🔤The given tree is not binary!🔤
🍉
↩️ 🔤🔤
🍉
🍉
Then rewrite the Depth-First Search Recursive Inorder Binary method to return an optional holding the enum and adjust the returns according to that:
❗️ 🍭 ➡️ 🍬⏹ 🍇
↪️ 🐔 children❗️ ▶️ 2 🍇
↩️ 🆕⏹⏫❗️
🍉
↪️ 🐔 children❗️ ▶️ 0 🍇
🍭🐽 children 0❗️❗️
😀 🔡 id 10❗️❗️
🍭🐽 children 1❗️❗️
🍉
🙅 🍇
😀 🔡 id 10❗️❗️
🍉
↩️ 🤷♀️
and then call the method like this:
️↪️ 🍭tree❗️ ➡️ return 🍇
😀 🔡return❗❗️️
🍉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems reasonable. Although — looking at this — a proper error handling mechanism for cases like this wouldn’t be a bad idea after all. Feel free to open an issue over at the Emojicode repo if you have ideas and time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, I used your suggested way of error handling for methods without a return value and opened an issue over at the emojicode repo: emojicode/emojicode#112 😀
0f9c86b
to
f244633
Compare
@thbwd Are you happy with the code after the latest changes? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! 👍 I hadn't received a notification about your changes, otherwise I would have approved this sooner, of course.
60a3fb0
to
0d36095
Compare
This is a combination of 5 commits. This is the 1st commit message: Add Tree Traversal in Emojicode This is the 2nd commit message: Remove unnecessary 🤜🤛. This was suggested by thbwd: "No need to wrap 🤜children_count🤛 into 🤜🤛actually." (https://github.com/algorithm-archivists/algorithm-archive/pull/ 471#discussion_r223291032) This is the 3rd commit message: Extract shared logic into a method. This was suggested by thbwd: "This is shared logic. I’d recommend you extract it into a method." (https://github.com/algorithm-archivists/algorithm-archive/pull/ 471#discussion_r223291140) This is the 4th commit message: Use documentation comments. This was suggested by thbwd: "Shouldn’t these be documentation comments? https://www.emojicode.org/ docs/reference/documentation.html" (https://github.com/algorithm-archivists/algorithm-archive/pull/ 471#discussion_r223291281) This is the 5th commit message: Add error as a potential return value for DFS RI Binary To be able to return an error and to apply suggestion by thbwd (https://github.com/algorithm-archivists/algorithm-archive/pull/ 471#discussion_r223597592) the following changes were made: - Declare an enum to hold the error value. - Rewrite the Depth-First Search Recursive Inorder Binary method to return an optional holding the enum and adjust the returns according to that. - Call the rewritten method and check, if the returned optional holds error. If it does: Print out the error message defined in the enum. Signed-off-by: Julian Schacher <jspp@posteo.net>
0d36095
to
50a8b94
Compare
@thbwd Awesome; thank you very much for the review! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ill merge this for you.
No description provided.