Skip to content

[Fix #1339] Add SerializableFunction support to ForEach on DSL#1340

Open
fjtirado wants to merge 1 commit intoserverlessworkflow:mainfrom
fjtirado:Fix_#1339
Open

[Fix #1339] Add SerializableFunction support to ForEach on DSL#1340
fjtirado wants to merge 1 commit intoserverlessworkflow:mainfrom
fjtirado:Fix_#1339

Conversation

@fjtirado
Copy link
Copy Markdown
Collaborator

Fix #1339

Function<T, Collection<?>> collection, Consumer<FuncTaskItemListBuilder> body) {
return list -> list.forEach(j -> j.collection(collection).tasks(body));
public static <T, V> FuncTaskConfigurer forEach(
SerializableFunction<T, Collection<V>> collection, Consumer<FuncTaskItemListBuilder> body) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I forgot this? :(

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Dont be hard on you, I also forgot when reviewing (;

private Optional<Class<?>> itemClass = Optional.empty();
private Optional<Class<?>> forClass = Optional.empty();
private Function<?, Collection<?>> collection;
private Function collection;
Copy link
Copy Markdown
Collaborator Author

@fjtirado fjtirado Apr 24, 2026

Choose a reason for hiding this comment

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

I sacrifice compile time type checkign here (which was kind of useless anyway) to have compile time type checking in user code.
In particular to verify that the type produce by the collection function matches the type expected by the single function parameter loop funcion.

…Each on DSL

Signed-off-by: fjtirado <ftirados@redhat.com>
Comment on lines +1031 to 1043
public static <T, V> FuncTaskConfigurer forEach(
SerializableFunction<T, Collection<V>> collection, LoopFunction<T, V, ?> function) {
return list ->
list.forEach(
j ->
j.collection(collection, ReflectionUtils.inferInputType(collection))
.tasks(function));
}

public static <T, V> FuncTaskConfigurer forEachItem(
SerializableFunction<T, Collection<V>> collection, Function<V, ?> function) {
return forEach(collection, ((t, v) -> function.apply((V) v)));
}
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Im adding these two ones, which are not directly related with the issue, but I think might be useful to cover most scenarion for users that want to use functions withint the loop (we were already covering the case for other constructs with the existing method)

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

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.

Experimental: Add SerializableFunction support to DSL for each method

3 participants