Skip to content
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

FR: List.filter() #5291

Open
msuozzo opened this issue Jan 8, 2025 · 0 comments
Open

FR: List.filter() #5291

msuozzo opened this issue Jan 8, 2025 · 0 comments
Labels
enhancement New feature or request

Comments

@msuozzo
Copy link

msuozzo commented Jan 8, 2025

Is your feature request related to a problem? Please describe.

I wanted to implement "labels" in a git commit message with lines of the form "label: value". Using the current Template functionality, adding a line is easy (concat(), String.join()) but removing is trickier. An LLM generated description.lines().filter(...) which looked correct before I tried it and discovered filter() was hallucinated.

Describe the solution you'd like
List.filter() in a similar form to List.map()

Describe alternatives you've considered
@bryceberger put together a workaround using List.map() which uses the empty string for excluded lines and moves the "gather" operation (join in this case) into the map expression.

description.lines().map(|line| if(<predicate>, line ++ "\n")).join("")

Still, there are clear limitations with this approach and I wouldn't expect it to be maintainable extending beyond a few successive calls. So while it does the trick, I think there's an opportunity to add a more ergonomic alternative.

Additional context
Discord discourse: https://discord.com/channels/968932220549103686/1326247959213506682

@yuja yuja added the enhancement New feature or request label Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants