Skip to content

builtins: add flatmap fn xs (tree-only HOF)#189

Merged
danieljohnmorris merged 2 commits into
mainfrom
fix/flatmap-builtin
May 13, 2026
Merged

builtins: add flatmap fn xs (tree-only HOF)#189
danieljohnmorris merged 2 commits into
mainfrom
fix/flatmap-builtin

Conversation

@danieljohnmorris
Copy link
Copy Markdown
Collaborator

map then flat was a frequent two-token pattern. flatmap fuses them into the natural shape for fan-out transforms where each input element produces zero or more outputs.

Implementation:

  • tree-only HOF, verifier enforces function literal in fn position
  • interpreter walks the lambda directly per element, concatenating results
  • no JIT opcode, tree interpreter only

Tests: cross-engine regression tests + examples/flatmap.ilo with -- run: directives.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 12, 2026

Codecov Report

❌ Patch coverage is 58.18182% with 23 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/interpreter/mod.rs 41.66% 14 Missing ⚠️
src/vm/compile_cranelift.rs 0.00% 4 Missing ⚠️
src/vm/mod.rs 0.00% 3 Missing ⚠️
src/verify.rs 94.73% 1 Missing ⚠️
src/vm/jit_cranelift.rs 0.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@danieljohnmorris danieljohnmorris force-pushed the fix/flatmap-builtin branch 2 times, most recently from 1d3b919 to 13e688e Compare May 12, 2026 09:46
map followed by flat was a frequent two-token pattern. flatmap fuses
them into one and is the natural shape for fan-out transforms where
each input element produces zero or more output elements.

Tree-only HOF: the verifier enforces a function literal in the fn
position, the interpreter walks it directly. No new opcode for the
JIT - the tree interpreter handles it.
Mirrors the uniqby coverage so a future refactor that drops the
flatmap verify arm gets caught on the VM dispatch path too.
@danieljohnmorris danieljohnmorris merged commit 86ffb30 into main May 13, 2026
4 of 5 checks passed
@danieljohnmorris danieljohnmorris deleted the fix/flatmap-builtin branch May 13, 2026 11:32
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.

1 participant