2626import io .serverlessworkflow .api .types .OAuth2AuthenticationData ;
2727import io .serverlessworkflow .api .types .func .ContextFunction ;
2828import io .serverlessworkflow .api .types .func .FilterFunction ;
29+ import io .serverlessworkflow .api .types .func .LoopFunction ;
2930import io .serverlessworkflow .fluent .func .FuncCallTaskBuilder ;
3031import io .serverlessworkflow .fluent .func .FuncEmitTaskBuilder ;
3132import io .serverlessworkflow .fluent .func .FuncRaiseTaskBuilder ;
@@ -1064,9 +1065,25 @@ public static FuncTaskConfigurer switchWhenOrElse(
10641065 * @param <T> input type for the collection function
10651066 * @return list configurer
10661067 */
1067- public static <T > FuncTaskConfigurer forEach (
1068- Function <T , Collection <?>> collection , Consumer <FuncTaskItemListBuilder > body ) {
1069- return list -> list .forEach (j -> j .collection (collection ).tasks (body ));
1068+ public static <T , V > FuncTaskConfigurer forEach (
1069+ SerializableFunction <T , Collection <V >> collection , Consumer <FuncTaskItemListBuilder > body ) {
1070+ return list ->
1071+ list .forEach (
1072+ j -> j .collection (collection , ReflectionUtils .inferInputType (collection )).tasks (body ));
1073+ }
1074+
1075+ public static <T , V > FuncTaskConfigurer forEach (
1076+ SerializableFunction <T , Collection <V >> collection , LoopFunction <T , V , ?> function ) {
1077+ return list ->
1078+ list .forEach (
1079+ j ->
1080+ j .collection (collection , ReflectionUtils .inferInputType (collection ))
1081+ .tasks (function ));
1082+ }
1083+
1084+ public static <T , V > FuncTaskConfigurer forEachItem (
1085+ SerializableFunction <T , Collection <V >> collection , Function <V , ?> function ) {
1086+ return forEach (collection , ((t , v ) -> function .apply ((V ) v )));
10701087 }
10711088
10721089 /**
@@ -1077,9 +1094,9 @@ public static <T> FuncTaskConfigurer forEach(
10771094 * @param <T> ignored (kept for signature consistency)
10781095 * @return list configurer
10791096 */
1080- public static <T > FuncTaskConfigurer forEach (
1081- Collection <? > collection , Consumer <FuncTaskItemListBuilder > body ) {
1082- Function <T , Collection <? >> f = ctx -> ( Collection <?>) collection ;
1097+ public static <T , V > FuncTaskConfigurer forEach (
1098+ Collection <V > collection , Consumer <FuncTaskItemListBuilder > body ) {
1099+ Function <T , Collection <V >> f = ctx -> collection ;
10831100 return list -> list .forEach (j -> j .collection (f ).tasks (body ));
10841101 }
10851102
0 commit comments