Skip to content

feat(api/iota): endofunctors#1191

Open
poolcritter wants to merge 1 commit into
FallingColors:mainfrom
poolcritter:push-nvtvkvszxopq
Open

feat(api/iota): endofunctors#1191
poolcritter wants to merge 1 commit into
FallingColors:mainfrom
poolcritter:push-nvtvkvszxopq

Conversation

@poolcritter

Copy link
Copy Markdown

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 #1083

@IridescentVoid IridescentVoid left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

github ate the comment I left on the file. see review below instead.

@github-project-automation github-project-automation Bot moved this from 📋 Backlog to 🏗 In progress in Hex Casting Jul 8, 2026

@IridescentVoid IridescentVoid left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 var for 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);

@IridescentVoid IridescentVoid added enhancement New feature or request 1.20 api API-related enhancements/bugs/optimizations labels Jul 8, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

1.20 api API-related enhancements/bugs/optimizations enhancement New feature or request

Projects

Status: 🏗 In progress

Development

Successfully merging this pull request may close these issues.

feat: add an iota walker / endofunctor method

2 participants