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

Add list transformation expression and effect #7028

Merged
merged 14 commits into from
Jan 1, 2025

Conversation

sovdeeth
Copy link
Member

@sovdeeth sovdeeth commented Sep 1, 2024

Description

Adds transformation/mapping syntaxes for lists:

(transform|map) %~objects% (using|with) <.+>
%~objects% (transformed|mapped) (using|with) \\[<.+>\\]
%~objects% (transformed|mapped) (using|with) \\(<.+>\\)

The effect only works on variable lists, but allows the indices of the list to be retained (if the expression is singular).
The expression works on any list, but naturally cannot retain indices.
If the expression is plural, this acts like flatMap, where x,y,z transformed with (a, b) will return a(x), b(x), a(y), b(y), a(z), b(z).

Also allows ExprFilter to use () as grouping markers as well as [].

I'm still not convinced on the syntax wording and would like opinions and alternatives!

(i know i touched ClassInfo but i'm not cleaning all of that up!)


Target Minecraft Versions: any
Requirements: none
Related Issues: closes #3573

@sovdeeth sovdeeth added feature Pull request adding a new feature. 2.10 Targeting a 2.10.X version release labels Sep 1, 2024
@Moderocky
Copy link
Member

I think this needs a much better description and examples because I honestly can't work out what it's actually for even when I'm reading the code for it.

@sovdeeth
Copy link
Member Author

sovdeeth commented Sep 4, 2024

I think this needs a much better description and examples because I honestly can't work out what it's actually for even when I'm reading the code for it.

I would welcome suggestions! I'm not really sure how i should go about improving the descriptions because I don't really know where the fault is. It makes sense to me, which is obvious otherwise i wouldn't have written it this way, but I'm not sure where it's failing for others.

To explain it in java terms, this expression/effect is equivalent to Stream#flatMap() where it takes in a function and applies to to each element in the list.

Copy link
Member

@cheeezburga cheeezburga left a comment

Choose a reason for hiding this comment

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

This is very sick, and very useful. Just some tiny, non-code related things.

src/test/skript/tests/syntaxes/effects/EffTransform.sk Outdated Show resolved Hide resolved
src/test/skript/tests/syntaxes/effects/EffTransform.sk Outdated Show resolved Hide resolved
src/test/skript/tests/syntaxes/effects/EffTransform.sk Outdated Show resolved Hide resolved
src/test/skript/tests/syntaxes/effects/EffTransform.sk Outdated Show resolved Hide resolved
src/test/skript/tests/syntaxes/effects/EffTransform.sk Outdated Show resolved Hide resolved
src/main/java/ch/njol/skript/sections/SecFilter.java Outdated Show resolved Hide resolved
src/main/java/ch/njol/skript/effects/EffSort.java Outdated Show resolved Hide resolved
sovdeeth and others added 2 commits September 4, 2024 10:48
Co-authored-by: cheeezburga <47320303+cheeezburga@users.noreply.github.com>
Copy link
Member

@Moderocky Moderocky left a comment

Choose a reason for hiding this comment

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

Description for transform syntax could still use some improvement. I suggested adding something like

Applies the given function to each element in the list, replacing the original element with the function's result.

but you might be able to come up with a better alternative (maybe function is a bad word since it's not actually a script function).

src/main/java/ch/njol/skript/effects/EffTransform.java Outdated Show resolved Hide resolved
Co-authored-by: Efy <35348263+Efnilite@users.noreply.github.com>
Copy link
Member

@APickledWalrus APickledWalrus left a comment

Choose a reason for hiding this comment

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

This is great work. A few thoughts 🙂

@Moderocky Moderocky added the feature-ready A PR/issue that has been approved, tested and can be merged/closed in the next feature version. label Dec 24, 2024
@APickledWalrus APickledWalrus merged commit a972a6f into SkriptLang:dev/feature Jan 1, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.10 Targeting a 2.10.X version release feature Pull request adding a new feature. feature-ready A PR/issue that has been approved, tested and can be merged/closed in the next feature version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants