feat(api/iota): endofunctors#1191
Open
poolcritter wants to merge 1 commit into
Open
Conversation
IridescentVoid
requested changes
Jul 8, 2026
IridescentVoid
requested changes
Jul 8, 2026
IridescentVoid
left a comment
Contributor
There was a problem hiding this comment.
Code-Review: -1
Implementation of visitChildren should be made more readable. I would like to at least see full-length variable names.
I'd also like feedback from others on the API design since changing this later would be a breaking change.
Comment on lines
+104
to
+114
| var o = new Iota[getList().size()]; | ||
| int w = 0; | ||
| boolean k = true; | ||
| var p = getList(); | ||
| while (p.getNonEmpty()) { | ||
| var r = visitor.apply(p.getCar()); | ||
| k &= r == p.getCar(); | ||
| o[w++] = r; | ||
| p = p.getCdr(); | ||
| } | ||
| return k ? this : new ListIota(Arrays.asList(o)); |
Contributor
There was a problem hiding this comment.
This section is pretty hard to read. I would suggest the following snippet instead, which should be equivalent. Changes I've made:
- Gave variables longer names.
- Use explicit types instead of
varfor slightly better readability. (IMHO, SpellList being written directly is better.) - Change the array to an ArrayList as
SpellList.size()is O(n). This also eliminates a piece of state that needs tracking, the index, which helps with code understanding. - Reordered some statements to follow what seemed to me as the most logical order.
Suggested change
| var o = new Iota[getList().size()]; | |
| int w = 0; | |
| boolean k = true; | |
| var p = getList(); | |
| while (p.getNonEmpty()) { | |
| var r = visitor.apply(p.getCar()); | |
| k &= r == p.getCar(); | |
| o[w++] = r; | |
| p = p.getCdr(); | |
| } | |
| return k ? this : new ListIota(Arrays.asList(o)); | |
| SpellList ptr = getList(); | |
| ArrayList<Iota> updatedChildren = new ArrayList<>(); | |
| boolean modified = false; | |
| while (ptr.getNonEmpty()) { | |
| var newChild = visitor.apply(ptr.getCar()); | |
| updatedChildren.add(newChild); | |
| modified = modified || newChild != ptr.getCar(); | |
| ptr = ptr.getCdr(); | |
| } | |
| return !modified ? this : new ListIota(updatedChildren); |
adds `visit` and `visitChildren` to iotas letting you apply a UnaryOperator to an entire tree of them. this is like hexal's IMappableIota except I don't know if that does self pre or post (or if it does self at all). awa. I haven't tested this in prod; hex doesn't have anything that would use this yet. @IridescentVoid I believe you have a patch that may want to use this? Cc: @IridescentVoid Change-Id: Ic464f4702ba9b0379c93e31723e2a5fe6a6a6964 Issue: closes FallingColors#1083
d8fddcb to
59bb512
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
adds
visitandvisitChildrento iotas letting you apply a UnaryOperator to an entire tree of them. this is like hexal's IMappableIota except I don't know if that does self pre or post (or if it does self at all). awa.I haven't tested this in prod; hex doesn't have anything that would use this yet. @IridescentVoid I believe you have a patch that may want to use this?
Cc: @IridescentVoid
Change-Id: Ic464f4702ba9b0379c93e31723e2a5fe6a6a6964
Issue: closes #1083