Hi everyone! I have a very long form and I’m using...
# arrow
f
Hi everyone! I have a very long form and I’m using
ValidatedNel<E, A>.zip
for validation. Unfortunately,
zip
accepts at most 9 arguments. Do you have any suggestions about using
Validated
with more than 9 arguments in an “nice” way?
Copy code
validatedArg0.zip(
  validatedArg1,
  validatedArg2,
  validatedArg3,
  validatedArg4,
  validatedArg5,
  validatedArg6,
  validatedArg7,
  validatedArg8,
  validatedArg9,
  ::someFunction
)
s
Copy code
/**
 * Returns a [Flow] whose values are generated with [transform] function by combining
 * the most recently emitted values by each flow.
 */
fun <T1, T2, T3, T4, T5, T6, R> combine(
        flow: Flow<T1>,
        flow2: Flow<T2>,
        flow3: Flow<T3>,
        flow4: Flow<T4>,
        flow5: Flow<T5>,
        flow6: Flow<T6>,
        transform: suspend (T1, T2, T3, T4, T5, T6) -> R
): Flow<R> = combine(flow, flow2, flow3, flow4, combine(flow5, flow6, ::Pair)) { r1, r2, r3, r4, (r5, r6) ->
    transform(r1, r2, r3, r4, r5, r6)
}
this is what I did for combining
Flow
(the coroutines lib has up to 5).... you can do something similar for
zip
f
Validated.zip
is not so easy as
Flow.combine
The only solution I can think of is splitting the validated arguments in blocks of 10 items using
Tuple10
and then using a destructuring declaration:
Copy code
validatedArg0.zip(
  validatedArg1,
  validatedArg2,
  validatedArg3,
  validatedArg4,
  validatedArg5,
  validatedArg6,
  validatedArg7,
  validatedArg8,
  validatedArg9,
  ::Tuple10
).zip(
  validatedArg10,
  validatedArg11
) {
  (arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9), arg10, arg11 ->
  // ...
}
👍 1